Working with multiple git remotes to share code with different teams


We are all familiar with the clone command

git clone repository_url

This creates a local working copy of the remote, identified by the short name origin. You can see all the remote repositories in your working copy thus

git remote -v

The following command fetches commits from origin

git pull

The following command pushes local commits to origin

git push

What if you want to share your copy of the repository so that another team can work on it? Maybe to a new remote repository shared with that team?

This can be done as follows

git remote add repo_short_name repository_url
git push repo_short_name

If that remote is an empty repository, the latter command will have to include the branch

git push repo_short_name master

You can pull changes from the new repository

git pull repo_short_name

And push them to origin

git push origin

If a remote has conflicting commits that you want to favor

git pull -s recursive -X theirs repo_short_name

For more information on working with remote repositories see chapter 2 of the free Git book.

Once you have mastered the command line, you can do all of the same things using a Git client such as the free SourceTree app from the folks at Atlassian.

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