Git
git branch -vv
check for remote repo connectiongit branch -r/-a
list remote/all branchesgit branch -u origin/<branch>
set the upstream branch for current branchgit blame <file-name>
check for contributorsgit cherry-pick <commit1> <commit2> ...
pick commits and append to current HEADgit config --global user.email "email@example.com"
git config --global user.name "Your Name"
git config --global alias.s status
usegit s
in short forgit status
git config --global push.default simple
git config --global pull.ff only
git config --global core.autocrlf true/false/input
git config --global --unset <entry-name>
unset global configurationgit clone -b <branch-name> --single-branch <url>
git commit --amend
re-commit the last commitgit checkout -
go to previous branchgit checkout <branch>/<commit-id>/<tag>
git checkout -b <branch>
create a new branch and checkout to itgit checkout -b <branch> origin/<branch>
also specify the upstream branchgit checkout <file-name>
undo a file to the last commit (valid beforegit add
this file)git clean <file-name> -f
remove untracked filegit clean <directory-name> -df
remove untracked directorygit clean -X -f
remove files ignored by.gitignore
git diff --staged/cached
diff between last commit and staged filesgit diff <id1> <id2>
git diff <branch1> <branch2>
git describe --tags --abbrev=0
most recent tag in current branchgit log --graph --pretty=oneline --decorate --all
git push --force
force update remote repo (overwrite commits in remote repo)git push origin master
will push local master to remote master, regardless of current branchgit push origin <source>:<destination>
push local source branch to remote destination branch wheresource
could also be a location represented byHEAD~1
ormaster^
git push origin :foo
push nothing to a remote branch foo will delete this branchgit fetch origin :foo
fetch nothing to a local branch foo will create this new branchgit pull
= git fetch + git merge; two branches in historygit pull --rebase
= git fetch + git rebase; a single line in history (recommended)git rm <file-name> -f
remove a staged file and delete it from file systemgit rm <file-name> --cached
remove a staged file but still keep it in working directorygit reset <file-name>
move a file from staging to working directorygit reset --hard/--soft/--mixed <commit-id>
git remote -v
to see the current remote URLgit remote set-url origin <newurl>
reset URL for origingit revert <commit-id>
go back to this commit by adding a new commitgit reflog
see all history operationsgit rebase <branch>
merge into a single line by making copies of new commitsgit rebase -i
interaction mode (can pick commits)git stash
git stash list/pop/apply/drop/clear
git show <branch-name>:<file-name>
git status --ignored
show files ignored by.gitignore
git tag <name>
git tag -ln
check for detailed infogit update-index --assume-unchanged <path/to/file>
untrack/hide a filegit update-index --no-assume-unchanged <path/to/file>
track/unhide a file
references: Version Control with Git; Learn Git Branching; How to undo almost anything with git
Last updated