0

For example, I clone step_06 of:

git clone -b step_06 https://github.com/Urigo/meteor-angular-socially

Now I want to replace step06's files with step07's files (on my machine). So I did:

git checkout -b step_07

cd meteor-angular-socially

git checkout -b step07

Switched to a new branch 'step_07'

However nothing actually changes in the folder/files.

What am I doing wrong?

Community
  • 1
  • 1
dragonmnl
  • 14,578
  • 33
  • 84
  • 129
  • 1
    Nothing should be change if you haven't commit any changes to the branch. You can see the current branch you are working on by running `git branch`. In your case this should return `*step_07` – Cyclonecode Aug 08 '15 at 09:54

1 Answers1

2

You are creating a new local branch instead of switching to the one from the remote repo.

git checkout step_07 should have been enough (from man git checkout):

If <branch> is not found but there does exist a tracking branch in exactly one remote (call it <remote>) with a matching name, treat as equivalent to:

git checkout -b <branch> --track <remote>/<branch>

Make sure to do a git fetch first, in order to get all remote branches.

But in your case, add git reset --hard origin/step_07

Here are the differences between step_06 and step_07, as reported by GitHub.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • thank you. it worked! can you please just clarify the command "git checkout -b --track /"? – dragonmnl Aug 08 '15 at 10:02
  • also, If I make some change to the local branch but then I request another branch. can I preserve the changes I made? – dragonmnl Aug 08 '15 at 10:04
  • @dragonmnl , If I make some change to the local branch but then I request another branch. can I preserve the changes I made? You would need to commit your local changes first. Then a checkout to another branch wouldn't lose those changes. – VonC Aug 08 '15 at 10:05
  • @dragonmnl see also https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches for the remote tracking aspect (also http://stackoverflow.com/a/25097913/6309) – VonC Aug 08 '15 at 10:06