creating a branch
git checkout -b nameOfNewBranch
creates a new local branch and checks it out.
If you want to pusblish your local branch, you have to
git push origin nameOfLocalBranch
git push --set-upstream origin nameOfLocalBranch
if you want to permanently set the remote path as upstream.
merging a branch
At some point you usually want to merge a branch into another branch, such as master.
If nothing changed on the original branch since you branched from it or if you did not publish your branch yet, then you may also consider to rebase your changes. If the original and your published branch diverged because there are changes on both branches, then you should not rebase as the reordering of changes may confuse people. See also our wiki page on rebasing vs. merging. Even if you rebase the changes of a branch, you still have to merge the branch itself. Therefore, the process is almost the same:
First, you have to be on the branch to be merged into another branch. We call the first branch mergee and the second branch mergeTarget to not confuse them:
git checkout mergee
If you are sure you want to rebase, you only have one additional command:
git rebase mergeTarget
Next, switch to the branch that is the target of your merge:
git checkout mergeTarget
Now, you can merge the branches (and also the changes if you did not rebase them before):
git merge mergee
Afterwards, you normally want to commit merged files and push the merge just like any other change.
If you don't need the mergee branch anymore, it's safe to delete it and to publish this deletion:
git branch -d mergee git push origin :mergee