This cheat sheet contains git commands, almost every developer use on daily basis. They will save you a lot of time and nerves.
(don't forget to add appropriate .gitignore
file to the root of the project beforehand)
git init
git add .
git commit -m 'Commit message'
git add -A
git commit -a -m 'Commit message'
git reset --hard
git clean -fd
git tag -a v0.5 -m 'Version 0.5 Stable'
git tag -a 1.0.1 <commit_id> -m 'Version 1.0.1'
git push --tags
git checkout <tag_name>
git tag -d v.0.4
git push origin :v0.4
git branch
git branch -r
git branch -a
git branch <branch_name>
git checkout -b <branch_name>
git branch <branch_name> commit_id
git checkout -b <branch_name> commit_id
git merge <branch_name>
git branch -D <branch_name>
git push origin --delete <branch_name>
or after deleting local branch:
git push origin :<branch_name>
git branch -m oldname newname
git push origin :oldname
git push origin newname
git fetch -p
git remote update origin --prune
git merge branch_name
git fetch origin
git reset --hard origin/master
git checkout v1.2.3 -- filename # tag v1.2.3
git checkout stable -- filename # stable branch
git checkout origin/master -- filename # upstream master
git checkout HEAD -- filename # the version from the most recent commit
git checkout HEAD^ -- filename # the version before the most recent commit
git rm --cached `git ls-files -i --exclude-standard`
or
git rm --cached `git ls-files -i --exclude-from=.gitignore`