Loading...

Jammie Mountz

Software Engineer

Git Workflow for Group Projects

During our second half of Hack Reactor, we are working in groups on the same project. Although ideally good group communication leads to working on features modularly, a good git workflow will also save headaches when committing to master. Merge conflicts can waste a lot of time!

Our group decided to use rebasing to keep all our code up to date with the commits on the master branch. We all belonged to an organization that had the master repo for the project, and then we each forked our own version and pulled that one down to work on locally. We set the organization’s master branch to be our local repo’s upstream master.

git remote add upstream www.git.repo.url

Once we had finished our work on our local repo and have added/committed the changes locally, we pull rebase to the upstream remote.

git pull --rebase upstream master

This command pulls down all of the commits made on the master that you don’t have locally. In a perfect world, that command runs without errors! However, occasionally you get a conflict with a commit on the upstream branch that has changed the same code you’re working on. The rebase will ‘pause,’ and you’ll be notified of the files that need to be fixed. Looking at those files, you’ll see three added lines –

HEAD >>>>>
... some code
>>>>>>
... some code
commit message >>>>>

You’ll need to compare the code in the first section (between HEAD and the >>> line) to the second section (between >>> and the commit message line) and decide how to fix it. Possibly, you’ll need some lines from one section and some from the other. Finally, you’ll delete those three lines from the code and git add that file to show you’ve made the changes.

Our strategy was to always address these merge conflicts with the other person who had written the conflicting code. Usually grabbing the person and going through the lines together would be a much quicker and error-free process than trying to figure it out yourself.

Now you’re able to continue the rebase:

git rebase --continue

And if your changes solve the problem, the rebasing will complete successfully! Now you can push to your github repo, and then merge that into the master.

Fluent in Spanish and JavaScript, salsa dancer, lover of material design.

Living in San Francisco, CA