Collaborating using git: make merging less painful!

Hi, I’m Shafiul! Me along with Ibrahim & Sifat are working in a project which we maintain using git. We’ve decided to follow a simple protocol to merge our works effeciently in a painless way!

All of us will work in our own branches (learn first about branching if you’re not familiar with it). At the end of the day, the one who finishes his work after the rest of the team, should merge all of our works!

Say, after working all day long, I figured out Ibrahim was still working before I went to bed. So it became Ibrahim’s due responsibility to merge everyone’s work ūüôā

The first step is: create a new branch for you, where only you will work, and no one else will touch.

Create a new Branch named “shafiul”:

git branch shafiul

To work in this branch, I need to check-out to work in this branch:

git checkout shafiul

While working, Commit any time:

git add -A
git commit -m "Message"

When you’re done, push your commits to the server:

git push origin shafiul:shafiul

Note the command: It pushes your commits made in local “shafiul” branch to origin’s (server’s) “shafiul” branch.

Like me, Ibrahim & Sifat has also crated their own branches named “ibrahim” & “sifat” and they’re working in their branches.

Merging everybody’s work

The one who will be merging has to do followings:
First, download everyone’s commits from origin (server) to his local machine:

git fetch origin shafiul:shafiul
git fetch origin ibrahim:ibrahim
git fetch origin sifat:sifat

Now time to merge. Check-out to master branch. With this branch, we will merge all other branches.

git checkout master

Now merge all other branches with master:

git merge shafiul
git merge ibrahim
git merge sifat

Cool! master is now merged with everyones code (Congratulations if no conflicts has occurred. But don’t get panicked if conflicts occur, to learn how to resolve conflicts, see the end of this article) – now Push your local “master” to origin (server):

git push origin master:master

Everyone’s duty: Update your branches…

The next day, before working, everyone should update their branches. First, everyone needs to pull updated “master” branch from origin (server) and merge it with your local copy of master branch:

git checkout master
git pull origin master:master

Now your local copy of master branch is updated. Finally, checkout to your own branch and merge it with updated master:

git checkout shafiul
git merge master


Send Commit Emails after users push in remote Git repository/server

Note: If you prefer to use terminal, you may need root access to use the following commands. If necessary, append “sudo” to all commands.

First, login to your remote server using ssh/ftp whatever. In your servers, say git repos are stored in /srv/gitosis/repositories directory (this is the default directory if you used gitosis).

Say, we’re interested in a repo called “myrepo.git” – it’d be available in /srv/gitosis/repositories/myrepo.git location.

Go to this folder. If you’re using terminal, you can type:

cd /srv/gitosis/repositories/myrepo.git

Some nice Description

Open file “description” and type whatever you want – text in this file will be sent in email’s subject as PROJECT NAME.

Mailing List

Open file “config” and add folowing text, configure to which addresses email will be sent as:

mailinglist =,        
showrev = "git show -C %s; echo"        
emailprefix = "[My Git Repo] "

Save the file. If you’re using terminal, you can open the files for editing using nano <filaname> command. When done editing, press Ctrl + x for exit, then press y for saving, press enter to use original file name for saving the file.

Activate Hooks

Now go to “hooks” directory & rename the file post-receive.sample to¬†post-receive:

cd hooks
mv post-receive.sample post-receive

Open the file (“post-receive”) for editing. Uncomment the last line by removing the beginning “#”, then save it.

Set Execute Permission on

Following 2 files should be made executable. I’m showing examples by terminal. If you’re using Filezilla/other file browser, make files “executable”, probably by right clicking on the files and clicking something like permission.

chmod 0755 /usr/share/doc/git-core/contrib/hooks/post-receive-email
chmod 0755 post-receive

That’s it! Now whenever someone pushes to the repo, emails will be sent according to the config file you’ve just edited.


Note: If the file “/usr/share/doc/git-core/contrib/hooks/post-receive-email” is missing, you can use following file downloading.;a=blob_plain;f=contrib/hooks/post-receive-email;h=60cbab65d3f8230be3041a13fac2fd9f9b3018d5;hb=HEAD