Using git to collaborate on a paper

I’m working with others on a paper written in LaTeX.  It’s stored in a git repository.  I figured it would be easy for all of us to track and merge each other’s changes this way.  So my friend clones the repo, commits a change, and sends me an email to let me know.  At this point, I thought, great, let’s grab his changes, review and merge them.

I’m sure this is obvious and is documented elsewhere, but it wasn’t to me. It’s not conceptually different than two programmers sharing code, which I’m sure is one of the common usages of git.

So I thought, well, I can just track his ‘master’ branch in my repo and merge the changes.

# this doesn't work
git branch --track friend-master/path/to/other/repo master

No, this doesn’t work.  I have to add my friend’s repo as a remote in my local repo first.

#this works
git remote add friend /path/to/other/repo

This says “Hey, I’m interested in the repo at /path/to/other/repo , and from now on I’m calling it “friend.” Does this mean I can track the branch now?

#not yet
git branch --track friend-master friend/master

No, first I have to fetch the remote so that my local repo is aware of what branches exist there.

#this grabs stuff from my friend's repo
git fetch friend

Specifying “friend” is necessary, because git will pull by your default repo if one is not specified (and your default is probably “origin”). At this point, we can track the branch and merge.

git merge friend/master


git remote add friend /path/to/other/repo
git fetch friend
git merge friend/master

It’s actually pretty simple. It might even be obvious, provided you already understand the way git works. Otherwise, you might find this useful.

About Daniel

I write distributed database software. Coding is fun. Love learning languages (spoken and computer). Always looking for opportunities to use advanced math in work and daily life. github: wangd
This entry was posted in development. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *