Phil
Phil

Reputation: 7106

Remaking a git branch

I am trying to remake a git branch. I want to recreate the branch from scratch, based off of the current master branch. I have done the following:

$ git status
# On branch foo
nothing to commit (working directory clean)
$ git checkout master
$ git branch -D foo
Deleted branch foo (was *******).
$ git push origin :foo
To git@***:***
 - [deleted]         foo
$ git checkout -b foo master
Switched to a new branch 'foo'
$ git push origin foo
To git@***:***
 * [new branch]      foo -> foo

Now, everything is working perfectly, for me at least. The problem is that other people who have worked with the "old" foo branch still have that copy. I have asked the others to do the following commands:

git checkout master
git branch -D foo
git checkout foo

Unfortunately, every time they checkout foo again, it is still tracking the old foo branch. What I usually do is just tell them to throw a git pull somewhere in the middle (without specifying branch), and it eventually works magically. What is the best way to tell git to track the "new" foo branch?

git version 1.7.4.1

Upvotes: 0

Views: 1442

Answers (1)

knittl
knittl

Reputation: 265443

You have to run git fetch at least once, otherwise the other git repositories have no knowledge of the "new" foo branch.

It's actually as easy as:

# on branch foo
git fetch
git reset --keep origin/foo

Upvotes: 1

Related Questions