tags:

views:

516

answers:

2

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?

+5  A: 

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.

Michael Krelin - hacker
"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
@Jon: The second instruction here will fetch all the tags from the remote. Note that you can also do `git fetch --tags <remote-url>`.
Jefromi
@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 <remote-url> <branch>`, or you can specify both the default remote and branch to merge using the config parameters `branch.<branchname>.remote` and `branch.<branchname>.merge`.
Jefromi
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
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
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
+1  A: 

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!

Adam Florin