When working with multiple people with git, is it better
For a medium to large size team, you most likely want to have centralized repository, with the "official" master
branch.
The other popular option would be to have an integrator, who is basically an intermediary between the developers and the central repo. How you decide upon this is reliant on what your team decides is the most appropriate method. There is a good write-up on the differences in the Pro Git book.
Going with a shared repo, it comes down to the developers personal preference (and some team agreement) whether to commit directly to their local master
, or use a separate dev
branch. My thought is that keeping local changes in a dev
branch is a better option, but slightly more cumbersome for developers who are used to centralized SCM.
The benefit of the separate dev
branch is that makes it easier to track new commits in the code base by just running git pull
on master
. The clean master lets the devs always check out the latest public code if necessary. If you pull
with changes in master
, it will merge in the origin/master
branch onto your unpublished commits. This will create a new merge commit in the master
and will be visible if the changes ever get pushed back to master
. Maybe this is what you want, but it can make the commit history somewhat messing looking.
With a dev
branch you can easily rebase against the master
to keep the commit history linear. Without a dev
branch, a git pull --rebase
in master
will have the same effect, but it is easy to forget this step.
Basically, using a private tracking branch (like dev
) gives a developer a little more flexibility on how she accepts public changes into her local branches. It also makes it easier to keep the centralized repo free of excessive merge commits. The only downside is that it requires some additional effort from the developers, but in the long-term will enhance the ultimate utilization of git.
Branch names in git are local to a repository. push
and pull
can be configured to match identical names on a remote repository, but that's optional behavior. If you have a central repository, you want master
there to be definitive. What individual developers call their working branches on their local repositories is really a matter of taste. Some will have their local master
be their working branch, and others will use a single named dev branch.
If your devs are up to it, the really savvy way is to use feature or topic branches, so that rather than having a "Mike's work" branch you have a "work on autofrotzification feature" branch that can be pushed and exchanged sanely without everyone needing to do a ton of early merging back and forth.
DVCS introduces the publication as an othogonal dimension to branching.
That means branches in a DVCS have two roles:
Git allows for "private commits", ie you commit as much as you want (and then you can clean your history of commits).
If you do that in master, this is not good for publication: since master is the branch visible by default when a repo is cloned, anyone cloning your repo won't get a stable state, but a snapshot of a work in progress.
Private commits means: commit in branches that aren't published.
You can call those whatever you want.
Any branch which is to be pushed/pulled should never be called after a resource name (like 'VonC_branch
'), but always after a feature or a more general release management topic (like 'public
', 'next
', 'patchV1
', ...)
The difference between the private branches and the public ones is the history of commits you allow in each one:
rebase --interactive
with !fixup
and !squash
actions)So to decide on how you will use branches with Git, you need to take into account the publication aspect.