In https://git-scm.com/book/en/v2/Git-Branching-Rebasing#_rebase_peril
It is recommended that rebasing should not be done when the repository is public.
And a recent post in git merge vs rebasing
recommends that rebase should not be done on branch shared between developers.
I understand that, because a developer might first merge the code and then he decides to rebase the code, other developers might end up in creating multiple duplicates commits as explained in Perils of Rebasing.
What if all developers come on a common agreement that everyone is going to always rebase the code instead of merging? Does the recommendation still apply?
P.S
All these answers confuse me. I think I will reframe the question again.
Let's assume that there is two developer working on two different computers. There is a central repository. The two developers cloned and started working.
Developer 1:
- Created a branch from local/master. Let's say local/iss123.
- Pushed it to remote
Developer 2:
- Pulled the changes from remote
- checksout to local/iss123
- Made some commits in local/iss123
- Pushed the changes to remote/iss123
Developer 1:
- Has some local commits
- He wants to rebase the branch with origin/iss123
- git rebase origin/iss123
- Then he pushes his commits to origin/iss123
Developer 2:
- Has some local commits
- He will rebase the branch with origin/iss123
- git rebase origin/iss123
and so on. Always developer 1 & 2 will rebase their branch with origin/branch then pushes their changes to origin/branch
After the functionality is stable, finally
Developer 1:
- checkouts to local/master
- pulls the latest code from origin/master
- checks whether there are any commits in local/master from other developers
- will checkout to local/iss123
- will rebase local/iss123 with local/master if there are any new commits.
- Then pushes the branch local/iss123 to remote/iss123 if there is a rebase done.
- Then checksout to local/master
- merges local/iss123 into local/master
- Then pushes local/master to origin/master
Developer 2:
- Will now pull the latest changes from origin/master and origin/iss123 to local/master and local/iss123 respectively
Later the cycle continues again.
Is this correct? Is this the right way when two developers are working on the same branch and always want to rebase instead of merging?