I have a local Git repository I\'ve been developing under for a few days: it has eighteen commits so far. Tonight, I created a private Github repository I was hoping to push
From Git 1.7.3 onwards, you can do this with one simple command:
git checkout -B master
The -b
switch means “create branch here before checking it out” and -B
is the unconditional version of that, “even if the branch already exists – in that case, move it here before checking it out”.
A very simple approach for fixing this sort of problem is to just delete the master
branch and recreate it. After all, branches in git are merely names for commits and the master
branch is nothing special.
So assuming that the current commit is the one you want master
to be, you simply do
git branch -D master
to delete the existing master
branch, then do
git checkout -b master
to a) create a new branch called master
that points to the current commit and b) update HEAD
to point to the master
branch. After that, HEAD
will be attached to master
and therefore master
will move forward whenever you commit.