Git cheat sheet saves you from learning all the commands by heart.
Be free to contribute, update the grammar mistakes. You are also free to add your language file.
- Set Up
- Configuration Files
- Create
- Local Changes
- Search
- Commit History
- Move / Rename
- Branches & Tags
- Update & Publish
- Merge & Rebase
- Undo
- Git Flow
git config --list
git config --local --list
git config --global --list
git config --system --list
git config --global user.name "[firstname lastname]"
git config --global user.email "[valid-email]"
git config --global color.ui auto
git config --global core.editor vi
<repo>/.git/config
~/.gitconfig
/etc/gitconfig
There are two ways
Via SSH
git clone ssh://user@domain.com/repo.git
Via HTTP
git clone http://domain.com/user/repo.git
git init
git init <directory>
git status
git diff
git diff <file>
git add .
git add -p <file>
git add <filename1> <filename2>
git commit -a
git commit
git commit -m 'message here'
git commit -am 'message here'
git commit --date="`date --date='n day ago'`" -am "<Commit Message Here>"
Don't amend published commits!
git commit -a --amend
Don't amend published commits!
git commit --amend --no-edit
GIT_COMMITTER_DATE="date" git commit --amend
git commit --amend --date="date"
git stash
git checkout branch2
git stash pop
git stash apply
- {stash_number} can be obtained from
git stash list
git stash apply stash@{stash_number}
git stash drop
git grep "Hello"
git grep "Hello" v2.5
git log -S 'keyword'
git log -S 'keyword' --pickaxe-regex
Show all commits, starting with newest (it'll show the hash, author information, date of commit and title of the commit)
git log
git log --oneline
git log --author="username"
git log -p <file>
git log --oneline <origin/master>..<remote/master> --left-right
git blame <file>
git reflog show
git reflog delete
Rename Index.txt to Index.html
git mv Index.txt Index.html
git branch
git branch -a
git branch -r
git checkout <branch>
git checkout <branch> -- <filename>
git checkout -b <branch>
git checkout -
git checkout -b <new_branch> <existing_branch>
git checkout <commit-hash> -b <new_branch_name>
git branch <new-branch>
git branch --track <new-branch> <remote-branch>
git branch -d <branch>
git branch -m <new_branch_name>
You will lose unmerged changes!
git branch -D <branch>
git tag <tag-name>
git tag -a <tag-name>
git tag <tag-name> -am 'message here'
git tag
git tag -n
git remote -v
git remote show <remote>
git remote add <remote> <url>
git remote rename <remote> <new_remote>
git remote rm <remote>
Note: git remote rm does not delete the remote repository from the server. It simply removes the remote and its references from your local repository.
git fetch <remote>
git remote pull <remote> <url>
git pull origin master
git pull --rebase <remote> <branch>
git push <remote> <branch>
git push <remote> :<branch> (since Git v1.5.0)
OR
git push <remote> --delete <branch> (since Git v1.7.0)
git push --tags
git config --global merge.tool meld
git mergetool
git merge <branch>
git branch --merged
Don't rebase published commit!
git rebase <branch>
git rebase --abort
git rebase --continue
git add <resolved-file>
git rm <resolved-file>
git rebase -i <commit-just-before-first>
Now replace this,
pick <commit_id>
pick <commit_id2>
pick <commit_id3>
to this,
pick <commit_id>
squash <commit_id2>
squash <commit_id3>
git reset --hard HEAD
git reset HEAD
git checkout HEAD <file>
git revert <commit>
git reset --hard <commit>
git reset --hard <remote/branch> e.g., upstream/master, origin/my-feature
git reset <commit>
git reset --keep <commit>
git rm -r --cached .
git add .
git commit -m "remove xyz file"