How to manage role of branch in Git? [closed]

Tag: git , git-branch Author: aguang15 Date: 2014-01-06

I'm using Git to manage my project but I had a problem with role of branches. Any branch in Git can push code of them to remote/master branch, so it make me confuse when I merge to stable versions. Because may be a developer pushed to my master branch.

possible duplicate of Git for beginners: The definitive practical guide
@FirstZero: thanks!
If it helps here is another website that I use - and if you prefer to see the merges visually - something like BitBucket, GitHub or Stash has pull requests so that you can see the merges and approve them.

Best Answer

In addition of basic branch management, you can:

  • make sure the remote doesn't accept non-fast-forward merge: so at least if a developer directly pushes new commits to origin/master, it would be commits easily merged to the new branch (that forces a developer to first rebase his/her work on top of origin/master before attempting a push).
    See "What's a “fast-forward” in Git?" and "Why does git use fast-forward merging by default?".

  • you can more easily separate dev branches by creating them in their own namespace: username/master instead of master, keeping master for being an (untouched) mirror image of origin/master.

  • you can add a description to a branch, leaving one more clue as to what that branch is for: see "Branch descriptions in git": git branch --edit-description. That information will be pushed along to a remote repo, for others to see.

  • finally, you can choose and follow a git workflow (like git-flow) in order to manage the convention around branch usage.


Good advice but I don't think the OP is knowledgeable enough to apply it. There's a lot of technicality like "fast-forward" etc. which will confuse rather than help.
@NoufalIbrahim you do realize that this answer is intended to be helpful to more than just the OP, right? Plus, those "technicalities" might prompt the OP to discover a bit more about Git, which is always good.
I do. My comment however, was mostly directed to the OP to whom your detailed answer might, in my opinion, seem overwhelming.
@NoufalIbrahim Then I agree with you; Hopefully, it will open new horizons for the OP or others in their Git discovery journey.
@NoufalIbrahim: sorry, what's OP means?