Skip to content

Git in a team.

July 2, 2008
So , after doing a little bit of homework, this is how I’m gonna do it. I’ll try the forking approach. Assuming that the repo is forked from a repo in github.Taken from Dr Nic’s website http://drnicwilliams.com/2008/02/03/using-git-within-a-team/

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:

git push

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.

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: