Create new branch
git checkout -b name_of_new_local_branch
Create new remote branch
git push origin name_of_new_remote_branch
Remove branch
git branch -d name_of_local_branch
Diff for last revision
git diff HEAD^
Diff for range of revisions
git diff hash1 hash2
Merge to master
git checkout master
git pull origin master
git merge name_of_local_branch
git push origin master
Tag list
git tag
Tag with name
git tag <tag_name> <hash_of_commit_to_be_tagged>
ReTagging/Update tag
git tag -a -f <tag_name> <hash>
Push tag to remote
git push origin <tag_name>
Remove tag from remote
git push --delete origin <tag_name>
Set upstream branch when remote doesn’t exist
git push -u origin name_of_branch
Set upstream branch when remote exist
git branch -u origin/remote_branch_name
Squash commits before push
git rebase -i <hash-commit-before-changes> (e.g. HEAD~2 – for two commits to squash. Second and later commit must be changed to squash or fixedup).
To push changes, sometimes need to use:
git push --force
Blame
git blame <hash/tag> -- <path_to_file> - hash is a starting point from which looks backward. To see previous file use “^” operator.
Log from give user
git log --author=UserName
Log for given hash
git show <hash>
Log for hash range
git log hash1..hash2 -–pretty=oneline
git log hash1..hash2 -–pretty=”%h date %cD %s”