#tl;dr
pre: assuming you have forked a repo and cloned your fork to your computer
git remote add [maintainer's name] [paste URL here]
git fetch --all
git branch --track [maintainer's name]_[branch] [remote name from step 1]/[branch you want to track]
At this point you may watch to checkout to your newly create branch and issue agit pull
command.
git checkout [maintainer's name]_[branch]
git pull
git checkout master
git merge [maintainer's name]_[branch]
====
These are notes for someone who has forked a Repository(Repo) on Github and would like to update their forked copy with updates from the Original Repo.
For example, Let's imagine that I have cloned jQuery to my Github Account. A few days later through some notifications, jQuery has updated the Repo with new code, after some review I decide that I want this code. People new to Github/Git would delete the fork that is on their own account, then just Fork the Repo again. While this would work, it is extremely uncool (we want to be cool, right?).
The steps below outline how to set up a branch, add a new remote
which points to the Original Repo, and then set up the branch to track the Original Repo, for easier and quicker updates. These steps are performed in your command-line interface and once set-up for a project, it takes at least 4 commands to update and merge in changes.
From here on out I will refer to the Original Repo as Maintainer's ...
.
git status
to ensure that you are working clean and can run the commands below. If your repo is not clean please do all the steps needed to get clean (e.g. commit, stash).
Go to the Original Repo's Github page and get the https
Clone URL. It should look something like https://github.com/jquery/jquery.git
With the URL copied to your clipboard. Run the command below in your Terminal. Here at DevLeague we prefer giving our tracking remote a name that includes the Original Repo's name followed by a _origin
suffix.
git remote add jquery_origin https://github.com/jquery/jquery.git
git remote add [maintainer's name] [paste URL here]
Make sure to run the fetch command, fetch goes and updates the history of a certain remote (and so much more)
git fetch jquery_origin
before: run the command git fetch --all
Our convention is to name the branch with the [maintainer's name] and a _[branch]
suffix.
git branch --track jquery_master jquery_origin/master
git branch --track [maintainer's name]_[branch] [remote name from step 2]/[branch you want to track]
git checkout [maintainer's name]_[branch]
Now that you've added a remote, created a new branch, and set that it (your newly created branch) to track a branch on the Original Repo. Now you can pull down changes!
git pull
You should see some changes mentioned in the Terminal.
Now checkout to your own local working branch and merge in the changes from your branch original repo tracking branch.
Once you have done all these steps for one repo, to get updates in the future all you need to do is Steps 4 & 5. If you have a new project, you MUST do all the steps over again to set up a tracking branch, new origin, etc.