-
Notifications
You must be signed in to change notification settings - Fork 26
Quick Reference
View all branches, local and remote
git branch -a
Checkout remote branch (making a local copy)
git checkout <RemoteBranchName>
Checkout (create new branch) based on existing local source
git checkout -b <NewBranch> <SourceBranch>
Bring in upstream updates from reference branch
git pull <RemoteName> <ReferenceBranch>
Initial commit of new feature branch to remote repository
git push --set-upstream <RemoteName> <NewFeatureBranch>
Delete branch from local repository
git branch -d <ObsoleteBranchName>
Update local listing of available remote branches
git remote update <RemoteName> --prune
View remotes
git remote -v
Change remote name
git remote rename <ExistingRemoteName> <DesiredRemoteName>
Add additional remotes
git remote add <Name> <URL>
Checkout a pull request as a branch
git fetch <RemoteName> pull/<PullRequestNumber>/head:<NewBranchName>
git checkout <NewBranchName>
Archive a branch as a tag (https://gist.github.com/zkiraly/c378a1a43d8be9c9a8f9 http://www.aaronwest.net/blog/index.cfm/2011/6/7/Git-Workflows-Archiving-Old-Branches)
-
Tag the unwanted branch
git tag archive/<UnwantedBranch> <UnwantedBranch>
-
Push the tag to the remote
git push --tags
-
Delete the branch locally and on remote
git branch -d <UnwantedBranch>
git push <RemoteName> :<UnwantedBranch>
-
Restore a deleted branch from a tag
git checkout -b <NameOfABranch> <tagName>