I have a fork of a project on github where the main trunk was recently tagged. I want to pull the code from the tagged revision into my fork. How would I do that?
-
1I'm a git newbie so I don't know all the terms yet... I want to merge the tagged code from the main trunk into my fork. If that's what git calls a "merge", then yes :) – Jon Kruger Aug 31 '09 at 11:57
-
You might also want to check out this question http://stackoverflow.com/questions/881092/how-to-merge-a-specific-commit-in-git – Vanuan Dec 22 '10 at 18:58
2 Answers
Once you have the tag in local repository you can do something like
git merge tags/yourtag
If you don't have the "trunk" tags locally, you can fetch it using
git fetch remote-url "refs/tags/*:refs/tags/*"
Or by setting up the remote
git remote add upstream remote-url
and fetching the stuff using
git fetch -t upstream
I think, though, using
git remote update
will have similar effect.

- 138,757
- 24
- 193
- 173
-
1"Once you have the tag in local repository" - how do I do this (I'm really a git newbie). What is the difference between "git merge" and "git fetch" and "git pull"? – Jon Kruger Aug 31 '09 at 13:39
-
1@Jon: The second instruction here will fetch all the tags from the remote. Note that you can also do `git fetch --tags
`. – Cascabel Aug 31 '09 at 14:04 -
2@Jon: `git pull` is a combination of `git fetch` and `git merge`. It uses `git fetch` to retrieve information (branch positions, commits, etc) from the remote repository, then uses `git merge` to merge the appropriate remote branch into the current local branch. You can specify the remote branch by doing `git pull
`, or you can specify both the default remote and branch to merge using the config parameters `branch. .remote` and `branch. .merge`. -
It worth noting, though, that `git pull` operates on branches and therefore will merge in the tip of the branch and not the tag in question. And to answer the question "how do I do this?" (get the local repository) — this is what everything beginning at "if you don't" deals with. – Michael Krelin - hacker Aug 31 '09 at 14:23
-
OK, I'm getting closer. I have the remote reference set up. Then I did "git fetch --tags myproject" and it got the tags. But now how do I get the source code that was labeled with a specific tag? – Jon Kruger Aug 31 '09 at 14:28
-
If you're on the branch where you want to merge it in, just invoke the first command in my answer. If you just want to start off of the tag, you can do a `git checkout -b mynewbranch tags/thattag`. – Michael Krelin - hacker Aug 31 '09 at 14:32
I may be projecting, but I think Jon's problem was the same as mine:
I forked someone else's project (on GitHub), and needed to point the master branch of my fork to a specific tag of their project, effectively ignoring all subsequent development. (Why? After that tag, their project dropped functionality that my fork depends on and must build on. So I'm pegged to that moment in history. Sad but true.)
In this example, the tag was called 0.6.3
. All I had to do was cd
to my local clone (of my fork) and do
git reset --hard 0.6.3
git push --force
Then I verified on GitHub that my fork reflected the state of the code at their tag!

- 1,345
- 1
- 11
- 12