Login or Sign up

git: move master branch to a new name and then checkout a remote branch to be master.

Posted by: skyl on Dec. 3, 2009

Instead of letting your master branch just run away from an upstream remote, you probably want to let a different branch run free while keeping your master branch tightly compatible with an upstream. Let's say you already corrupted you master branch but you don't want to give up all of that great history.

The following is the strategy I used to follow the Pinax docs for contributing (after I had been doing things differently for ~80 commits).

First, move your master branch to another name:

$ git branch -m master skyl-runaway

Now, fetch the remote that you want to track:

$ git fetch pinax

Checkout the master branch and track it:

$ git checkout -t pinax/master

Force the push to your remote:

$ git push origin +master

Now, let's add your old branch (now renamed) to the remote repository:

$ git checkout skyl-runaway
$ git push origin skyl-runaway

We are now free to git checkout master (and have the regular pinax) and git checkout skyl-runaway to work on our special sauce branch. For someone just cloning the repository, they will need to checkout the remote branch to a local branch to start working on it and have access to it.

Checkout the repository and change into the directory:

$ git clone git://github.com/skyl/pinax.git skyl-unpriv
$ cd skyl-unpriv

You can then see all of the possible branches with git-branch:

git branch -a

Then, to create a new branch from a remote branch, you will run something akin to:

git checkout -b skyl origin/skyl-runaway

The unprivileged user is now on the branch skyl.

Look at the git docs and man pages if you get stuck. Also, #git on irc is a friendly place.

Comments on This Post:

Please Login (or Sign Up) to leave a comment