Roni Yaniv Roni Yaniv - 2 months ago 4x
Git Question

Push a new local branch to a remote Git repository and track it too

I want to be able to do the following:

  1. Create a local branch based on some other (remote or local) branch (via
    git branch
    git checkout -b

  2. Push the local branch
    to the remote repository (publish), but make it
    trackable so
    git pull
    git push
    will work immediately.

How do I do that?

I know about
in Git 1.7, but that is a post-creation action. I want to find a way to make a similar change when pushing the branch to the remote repository.


In recent versions of Git (1.7.0 and later), you can checkout a new branch:

git checkout -b <branch>

Edit files, add and commit. Then push with the -u option:

git push -u origin <branch>

Git will set up the tracking information during the push.