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:

  1. To make sure it's safe on another server (for backup).
  2. To let others review it.
  3. 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
    OR
    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.
    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
    git checkout --track origin/[branch]
  • OR if you have commit access to the upstream branch
    git push -u upstream foo
    git push -u origin foo
  • When you need to, delete the branch
    • Locally
      git branch -d [branch]  # If it's been merged
      git branch -D [branch]  # unconditionally
    • Remote
      git push origin :[branch]  # pretty odd syntax

3 Comments

Randy,

Randy,

I love your recent burst of git discussion and documentation.

Keep up the great work!

-AC

git brandy^H^Hch

git brandy^H^Hch
Laughed so hard.

What fun. Had a dog named

What fun. Had a dog named Brandy for years. Not sure where that got in my fingers :-)