Naveen Kumar
Naveen Kumar

Reputation: 2980

How do I update a GitHub forked repository to a specific branch/tag?

I want to upgrade a forked repo which I forked 1 year ago to a specific tag. Anyone know how to do this ?

Upvotes: 2

Views: 1067

Answers (3)

serkan
serkan

Reputation: 131

Let's do it step by step:

  1. Fork the github repository
  2. Download your github repository to local computer. Example
git clone [email protected]:[user_name]/[repo_name].git
  1. Go to the local repo you downloaded and add the forked repo as a remote connection.
cd [repo_name]
git remote add upstream [email protected]:[Username_forked_repo]/[repo_name].git
  1. Pull the repo with the fetch command. Confirm that all branches have been pulled with the git branch -r command
git fetch upstream
  1. Pull all remote braches to local
git branch -r | grep -v '\->' | sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" | grep -E 'upstream/' | while read remote; do git branch --track "${remote#upstream/}" "$remote"; done
  1. Send all branches to github
git push --all origin
  1. Send all tags to github
git push origin --tags

Upvotes: 0

Naveen Kumar
Naveen Kumar

Reputation: 2980

I solved my problem by following these steps:

  • git checkout master
  • git remote add upstream <origianl_repo_link>
  • git fetch upstream
  • git rebase --onto tags/<tag_name> upstream/master master

Upvotes: 0

flyx
flyx

Reputation: 39638

If you did not already do that:

  • Clone the forked repository on your machine.
  • Add an upstream remote to the original repository (git remote add upstream <url>)

Then:

  • git fetch upstream --tags
  • git checkout -b <branchname> <tagname>

After that, you will have a new branch named branchname which is at the same state as the tag. Finally,

  • git push origin <branchname>

pushes the new branch to your GitHub fork of the repository.

(I assume this is what you want; if you just want to have the tags in your fork, use git push origin --tags)

Upvotes: 6

Related Questions