List of Useful Git commands
###Visualize commits
gitk --all &
###List All Branches
git branch <branchName>
###See hidden branches
git branch -a
###Create a branch without checking out to that branch
git branch <branchName>
###Create and check out to a branch
git checkout -b <branchName>
###Safely delete a branch
git branch -d <branchName>
###Delete a branch even with unmerged changes
git branch -D <branchName>
###Merging with another branch go to target branch
git merge <source-branchName>
###Base branch on another branch git checkout -b <branchName> <branchToBaseFrom>
###Checkout a remote branch and setup local tracking
git checkout -b <branchName> origin/<branchName>
Alternative (shorter) way to checkout an existing remote branch
git checkout <branchName>
###Stash changes
git stash
do your stuff and then revert back
git stash pop
###Pull in remote branch
git fetch <remoteName>
###Trace File history
git blame <fileName>
###Deleting a branch from remote
git push origin --delete <branchName>
###Push a local branch to remote
git push -u origin <branchName>
git log --pretty=oneline
###Git tags to list tags
git tag
to add tag
git tag <tagName>
git push origin --tags
delete tag
git tag -d <tagName>
delete tag on remote
git push origin :refs/tags/<tagName>
###Undo commits Undo one commit
git reset HEAD
Undo a number of commits
git reset --hard HEAD~3
Rename branch
git branch -m <branch>
Delete a remote
git remote rm
Add a new Remote git remote add origin-br git@github.com:blueraster/gfw-commodities-app.git
Track current branch to a different remote branch git branch -u origin-br <branchName>
git branch develop-br -u origin-br/master git branch --set-upstream develop-br origin-br/master
*Pull from remote branch into current branch git pull origin-br <remoteBranchName> git pull origin-br master;
*Push current branch to remote branch git push origin-br <remoteBranchName> git push origin-br develop-br;
Steps to Push to different Repo's Remote Branch git checkout -b develop-br git remote add origin-br git@github.com:blueraster/gfw-commodities-app.git git pull origin-br master git push origin-br develop-br;