How to use git in a mutli-user environment,

Started by
5 comments, last by Bregma 11 years, 3 months ago

Hello everyone and Merry Christmas,

Me and a friend have started working on some stuff together and we've decided to use git as our version control system. We keep running into issues with fast-forward errors. We're both working in one branch (master) and we often commit and push at the same time.

I'm wondering how we should best make use of egit on eclipse to try and avoid these issues. We're hosting on bitbucket if that helps. Should we both work in local branches then merge them before pushing or something like that?

There is very little information from what I can see on this (maybe I'm just wording it wrong in Google and I would really appreciate some really in depth articles that describe it well, plus if they have a focus on egit as well that would be awesome, but it's by no means necessary.

Any help would be greatly appreciated. Thanks!

Advertisement

Doing some more searching I found this. Looks interesting and sort of describes what I'm looking at. I would still really love some good articles so if anyone has anything It would be really great.

Thanks.

Well, yes, git is not google docs. What's happening is that initially, your two local repositories (the one on your computer and on your friend's) are synchronized, but when your friend pushes his modifications to the main repository, that repository is now out of date with yours, and when you try to push your own modifications, the push will probably fail since your repository is out of date. In this case you need to update your repository (git pull) and hope that doesn't trash your work in case your friend was working with the same files you were. Then you should be able to push (unless your friend pushed again since then, as you can see this can be frustrating).

A good idea is to not push as often - prefer to just commit, which only makes changes to your local repository, and only push once you've accomplished enough work and your friend can update his repository (hopefully you didn't write over what he is currently working on - good project management will prevent that). In fact, ideally since you are working on unrelated features of a modular system, people don't need to pull your modifications to keep working, unless it's a major bug that affects the entire codebase. They'll just do their own stuff, push to their respective files and the end user can then grab the most up to date repository, regardless of who's done or not. This doesn't directly apply to you, obviously, since on a two-man team the code you're working on will likely be very related, but the idea still stands - don't push unless your friend needs your code to keep working (or you are finished for the day).

Another approach is to push to an integration manager (as you saw on those links above) which'll optionally decide what to pull into the repository (for non-trusted collaborators) and merge everything together correctly, in case you were working on the same things. This is important in big projects with lots of random collaborators, since people don't communicate as much between one another and you can't just trust people to behave properly and not break each other's code, so you have a "gatekeeper" which prevents that.

The bottom line being that there is no good way to work together on the same piece of code, really. The whole point of collaboration is to get work done faster, and you can't achieve that by having people fight over the same lines of code. It's like asking nine woman to have a baby in a month, it doesn't work that way. So perhaps for a two-man team you could try to divide your work by having your game logic (is it a game you're making?) flexible, accepting well-defined interfaces to whatever modules you are going to use, and then have him work on the character system while you get the graphics up and running, etc.. does that make sense?

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Why not use three branches (master, one for you and one for your friend)? That way, you can both push the code. When made sure that your code in your branch does work, you can merge your branch to master. After that, your friend can merge master to his branch and continue working happily.

I've thought of branching, but I wondered if it was the appropriate thing to have a branch per developer. I saw in the link I found that in git, you can fetch then merge, then push which means you won't get a non-fast-forward error.

<blockquote class="ipsBlockquote" data-author="TheCreeperLawyer" data-cid="5014370"><p>I've thought of branching, but I wondered if it was the appropriate thing to have a branch per developer. I saw in the link I found that in git, you can fetch then merge, then push which means you won't get a non-fast-forward error.</p></blockquote><br />Thats pretty much what we do, commit -&gt; pull -&gt; push , git merges changes automatically even if they are made to the same file. Branches are only made to separate development of new features from maintaining the stable release.
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

You should probably understand there is no such concept of a "master" branch in git. You might have a local repo with one or more branches, your friend might have a local repo with one or more brances, there might be a repo at bitbucket with one or more branches. You'll probably designate one of the branches at bitbucket as the one from which releases are made. You probably work with one of your local branches. there is nothing special about any of those branches except how you have decided to use them.

In my experience, the best practice with git is to have a local copy of the designated release branch locally, and have that one labeled 'master' (which is the default label for a newly created branch in a repo and easily created from the remote release branch using 'git clone'). Do your work on a separate local branch called 'develop', and even use feature branches from that branch for individual features. Branching is very very cheap in git, more branches are better. Before pushing your work up to the release branch, synchronize your local copy ('master') with the remote, then merge your work on to it (fixing any conflicts if necessary). The, push that to the remote release branch.

I've found this to be a nice workflow for any DVCS.

Stephen M. Webb
Professional Free Software Developer

This topic is closed to new replies.

Advertisement