Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is it bad practice to commit to your fork's master branch?

Most Git workflows say to never commit to your fork's master because then your master branch will diverge from origin. However, wouldn't it work to just rebase your commits (from your master branch) on the upstream's master? I know it's a little more complicated, but I don't see why this is bad practice.

like image 582
rb612 Avatar asked Nov 17 '15 05:11

rb612


People also ask

Why you shouldn't commit directly to master?

Not committing to master prevents colliding commits and having to merge each time 2 people change the same file.

Is pushing to master bad?

Yes it is a bad practice, Ideally there should not be any direct commit in master branch.

When should you commit to master?

Your first commit to master should be an empty repository. Your next commit to master should be a merge commit from the develop branch or a temporary release branch, and it should be stable, tested, and ready for deployment (if it's an application) or public distribution (if it's a library).

How do you commit changes to the master branch?

If you are on a feature branch, you can checkout to the master branch and then merge your feature branch - git checkout master and then git merge <feature branch> , and then push your changes again using git push origin master .


2 Answers

Most people would probably not want to rebase every time they want to pull from upstream because you lose some history metadata (timestamps, potential squashing, etc). But for other people this may not be an issue.

Another reason would be for pull-requests. Ideally, you would have the content of your pull-request on a topic branch which then (hopefully) get's merged into your upstream, after which you simply delete that topic branch and pull from master. This way you don't have your old (now duplicated) commits still in your history.

There is something to be said in the ability to be able to keep your master branch "pure" in the sense that anytime you want to can pull your master and have no conflicts. This way 6 months after you fork you can still at a single glance see what is "theirs" and what is "yours".

like image 58
Jonathan.Brink Avatar answered Sep 21 '22 10:09

Jonathan.Brink


It is technically possible, but confusing for the maintainer of the original repo.

  • any branch from the original repo should be updated by a git fetch upstream (not by your own fork as well)
  • When you do a PR, the name of the branch is important to isolate and characterize the nature of your PR
like image 36
VonC Avatar answered Sep 17 '22 10:09

VonC