This page documents and gives examples of how to work with branches in git:
git branch -a
All local and remote branches are visible in the sidebar. Use Fetch to update the list of remote branches.
Note! This can be done with uncommited chenges. All changes will still be there for you to commit on the new branch.
git checkout -b <branch>
First make sure that you’re currently on the branch that you want to use as base for the new branch. Click on the Branch button in the toolbar and enter a name for the new branch. Use
/ to create ”subdirectories”.
git checkout <branch>
To switch to another branch, right-click on it’s name in the sidebar and choose the Checkout <branchname> option from the context menu. If you do this on a remote branch you will be asked to create a local copy.
git stash git checkout <branch> git stash pop
git merge <branch>
Conflicts occur when two commits make changes to the same parts of a file. Example:
These conflicts can be a bit tricky to solve. In many cases you want to keep both changes. Atom has built in support for handling merge conflicts.
Our changes come from the current branch and Their changes are from the other branch that you’re merging from.
On the branch
git branch -m new-name
On another branch
git branch -m old-name new-name
Delete the old-name remote branch and push the new-name local branch.
git push origin :old-name new-name
Reset the upstream branch for the new-name local branch. (when on branch)
git push origin -u new-name
git branch -d <branch_name>
git push origin --delete <branch_name>
git push origin :<branch_name>
After a while you have created a bunch of branches and some have been created as a pull-request which has been successfully merged. Since your terminal will try to give hints which local branch you may checkout the suggestions may grow even if the branch is no longer present on the origin.
git checkout master && git pull
git branch --merged | egrep -v "(^\*|master|dev|stage)"
git branch --merged | egrep -v "(^\*|master|dev|stage)" | xargs git branch -d