Pushing and Deleting Git Topic Branches (Screencast)
Creating topic branches (also called "feature branches") is easy in Git and
is one of the best things about Git. Sometimes we also want to get those pushed
from our local repo for various reasons:
- To make sure it's safe on another server (for backup).
- To let others review it.
- To let others build upon it.
Here we'll just be dealing with #1 and #2, and not talking about how to collaborate
on a shared branch. We'll be assuming that only the original author will push to it,
and that nobody else will be doing work based on that branch.
- Creating a feature branch (using name/name_issue)
git checkout -b rfay/some_feature_39949494/05<br>OR<br>git checkout -b rfay/some_feature_39949494
- Pushing it up (with origin xxx)
git push origin rfay/some_feature_39949494
- Turning a regular branch into a tracking branch (if you like shorter commands)
git config --global push.default tracking # One time setup.<br>git branch --set-upstream foo upstream/foo
- OR just create a new tracking branch and forget all that.
git branch -m [my_current_branch] junk<br>git checkout --track origin/[branch]
- OR if you have commit access to the upstream branch
git push -u upstream foo<br>git push -u origin foo
- When you need to, delete the branch
- Locally
git branch -d [branch] # If it's been merged<br>git branch -D [branch] # unconditionally
- Remote
git push origin :[branch] # pretty odd syntax
- Locally
Original Article: