Top 20 Git Commands
Top 20 Git Commands
dzone.com/articles/top-20-git-commands-with-examples
git config
git clone
git add
git commit
git diff
git reset
git status
git rm
git log
git show
git tag
git branch
git checkout
git merge
git remote
git push
git pull
git stash
Git Commands
git config
Usage: git config –global user.name “[name]”
This command sets the author name and email address respectively to be used with your
commits.
git init
Usage: git init [repository name]
1/9
git clone
Usage: git clone [url]
git add
Usage: git add [file]
git commit
Usage: git commit -m “[ Type in the commit message]”
This command records or snapshots the file permanently in the version history.
This command commits any files you’ve added with the git add command and also
commits any files you’ve changed since then.
2/9
git diff
Usage: git diff
This command shows the file differences which are not yet staged.
This command shows the differences between the files in the staging area and the latest
version present.
This command shows the differences between the two branches mentioned.
git reset
Usage: git reset [file]
This command unstages the file, but it preserves the file contents.
3/9
Usage: git reset [commit]
This command undoes all the commits after the specified commit and preserves the
changes locally.
Usage: git reset –hard [commit] This command discards all history and goes back
to the specified commit.
git status
Usage: git status
git rm
This command deletes the file from your working directory and stages the deletion.
git log
This command is used to list the version history for the current branch.
4/9
Usage: git log –follow[file]
This command lists version history for a file, including the renaming of files also.
git show
Usage: git show [commit]
This command shows the metadata and content changes of the specified commit.
5/9
git tag
Usage: git tag [commitID]
git branch
Usage: git branch
This command lists all the local branches in the current repository.
git checkout
Usage: git checkout [branch name]
6/9
This command is used to switch from one branch to another.
git merge
Usage: git merge [branch name]
This command merges the specified branch’s history into the current branch.
git remote
This command is used to connect your local repository to the remote server.
git push
Usage: git push [variable name] master
This command sends the committed changes of master branch to your remote repository.
7/9
Usage: git push –all [variable name]
git pull
Usage: git pull [Repository Link]
This command fetches and merges changes on the remote server to your working
directory.
git stash
Usage: git stash save
8/9
This command restores the most recently stashed files.
9/9