Git
Commands
git config
Example: git config –global user.name
“[name]”
Example: git config –global user.email
“[email address]”
This command sets the author name/email address to be used with the commits.
git
init
Example: git init [repository name]
This command is used to start a new
repository.
git
clone
Example: git clone <path>
This command is used to obtain a repository
from an existing URL path.
git
add
Example: git add . ( . Adds all the files to staging area)
This command adds files to the staging.
Example: git add *
This command adds one or more files to the staging area.
git
commit
Example: git commit -am “[ Type in the
commit message]”
This command commit the data into
local branch from staging files.
Example: git commit -a
This command commits any files you’ve
added with the git add command and also commits any files you’ve changed.
git
diff
Example: git diff
This command shows the file
differences which are not yet staged.
Example: git diff –staged
This command shows the differences
between the files in the staging area and the latest version.
Example: git diff [first branch]
[second branch]
This command shows the differences
between the two branches mentioned.
git
reset
Example: git reset [file]
This command unstages the file, but it
preserves the file contents.
Example: git reset [commit]
This command undo all the commits
after the specified commit and preserves the changes locally.
Example: git reset –hard [commit]
This command discards all history and
goes back to the specified commit.
git
status
Example: git status
This command shows all the files that
have to be committed and staged already.
git rm
Example: git rm [file]
This command deletes the file from your working directory and stages the deletion.
git
log
Example: git log
This command is used to list the
version history for the current branch.
Example: git log –follow[file]
This command lists version history for
a file, including the renaming of files also.
git
show
Example: git show [commit]
This command shows the metadata and
content changes of the specified commit.
git
tag
Example: git tag [commitid]
This command is used to give tags to
the specified commit.
git
branch
Example: git branch
This command lists all the local
branches in the current repository.
Example: git branch [branch name]
This command creates a new branch.
Example: git branch -d [branch
name]
This command deletes the feature
branch.
git
checkout
Example: git checkout [branch
name]
This command is used to switch from
one branch to another.
Example: git checkout -b [branch
name]
This command creates a new branch and
also switches to it.
git
merge
Example: git merge [branch name]
This command merges the specified
branch’s history into the current branch.
git
remote
Example: git remote add [variable
name] [Remote Server Link]
This command is used to connect your
local repository to the remote server.
git
push
Example: git push [variable name]
master
This command sends the committed
changes of master branch to your remote repository.
Example: git push [variable name]
[branch]
This command sends the branch commits
to your remote repository.
Example: git push –all [variable
name]
This command pushes all branches to
your remote repository.
Example: git push [variable name]
:[branch name]
This command deletes a branch on your
remote repository.
git
pull
Example: git pull [Repository
Link]
This command fetches and merges changes on the remote server to your working directory.
git
stash
Example: git stash save
This command temporarily stores all
the modified tracked files.
Example: git stash pop
This command restores the most
recently stashed files.
Example: git stash list
This command lists all stashed
changesets.
Example: git stash drop
This command discards the most
recently stashed changeset.
Comments
Post a Comment