9

There is a branch on remote I would like to work on. It is old and I no longer have an old copy of it on my local machine. It is really far behind master. Whenever I attempt to pull it I get conflicts. I just want to create an exact duplicate of the remote branch on my local system. Why would that lead to conflicts?

I tried:

git pull origin branch_name:branch_name

That created a new branch on my local machine with the right name, but it led to conflicts.

Bjorn
  • 69,215
  • 39
  • 136
  • 164

4 Answers4

10
git fetch origin
git checkout -b newoldbranch oldoldbranch
Michael Krelin - hacker
  • 138,757
  • 24
  • 193
  • 173
5

git pull repo branch is basically shorthand for git fetch repo branch and git merge repo/branch. I'm not one to often say RTFM, especially with git, but it is the first line of the git-pull docs. "git-pull - Fetch from and merge with another repository or a local branch". The implicit merge is causing the conflict. You just want a fetch & checkout as Michael said.

Schwern
  • 153,029
  • 25
  • 195
  • 336
  • 2
    Yeah, it'll do that. Trust me, its worth the effort. So much simpler than SVN once you get it. – Schwern Dec 21 '09 at 07:37
3

Can't you simply check it out ?

git checkout branch_name

?

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
  • 1
    This sort of worked, but I had to change it: git branch branch_name origin/branch_name git checkout branch_name – Bjorn Dec 18 '09 at 21:44
  • 1
    It's not that I mind, but isn't it funny that you accepted this answer, although you had to change it to mine? ;-) git branch + git checkout is equivalent to git checkout -b ;-) – Michael Krelin - hacker Dec 19 '09 at 21:46
0

I like to change to another local branch, remove an existing one where I want to pull (for example task_branch), and change again:

  • git checkout - // changing to previous branch, or just git checkout master
  • git branch -D task_branch // remove local branch
  • git fetch // fetch data from remote
  • git checkout task_branch // change to the branch with the newest changes

and optionally check if everything is up to date by git pull

Ridd
  • 10,701
  • 3
  • 19
  • 20