Forking is to clone an entire remote repository into another
remote repository. Now you have two repositories based around the
same code base. At that one point in time, they have the same set of
files and the same history of changes.
In our case, you’d fork a git repo. Then, you do a git clone of the repo that you’d just forked.
To you, once you’ve forked a repository, then your repository is
your git “origin” and the original repository you forked just
becomes a fork to pull from when you want to synchronise your
repositories. Make sense? Thought so.
At your local machine terminal,
git clone <your_forked_git_repo>
Now, you have your own local repo.
But what if others makes a change to the code? Well, you need to track their changes. Here is how … base on this website.. (http://railsontherun.com/2008/3/3/how-to-use-github-and-submit-a-patch)
Enter the following at your own local repo.
git remote add main_repo <the_git_repo_that_you’d_fork_from>
This will add information in your .git/config of another remote repository that you like to remain updated in your local repo.
Then, the following:
git fetch main_repo
The following output will come out
From <the_git_repo_that_you’d_fork_from>
* [new branch] master -> main_repo/master
Then, do this:
git checkout -b main_repo main_repo/master
The command tells git to create a new branch name main_repo and checkout to that repo.
The following output will come out:
Branch main_repo set up to track remote branch refs/remotes/main_repo/master.
Switched to a new branch “main_repo”
If you do
git branch
You’ll see this:
* main_repo
master
The asterisk shows which branch you’re currently in.
If you do
git branch -r
You’ll see the following
main_repo/master
main_repo/no_signup
origin/HEAD
origin/master
origin/no_signup
The origin is your remote repo, while the main_repo is from the repo that you’ve just forked.
To pull from the main_repo, make sure you’re in the main_repo branch first.
To switch to the main repo branch:
git checkout main_repo
Then pull from the main_repo codes:
git pull main_repo
Then, switch back to your master branch
git checkout master
So to merge the main_repo branch to your master. (Make sure you commit your work first before merging with the main repo.)
git merge main_repo
If there’s conflict, if you’re sure about what’s need to be resolve then code away. Git will tell you which files are in conflict state.
So after you’ve done with your codes. It’s time to push it. Again, make sure you’re in your master branch. Just do:
Then, notify the main_repo maintainer to pull from your repo.
This is one way to work within a team that I know. Maybe in time, I’ll find a better way to work with git much more efficiently.

