Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - multiple developers on same branch

I am pretty new to Git and I am using sourcetree as a client.

I know that in Git two developers work on the same branch at a time since they have local copies of the remote branch.

So here is a scenario :

A and B are working on a branch feature/release1.0

A commits code to local branch. Now B commits the code and pushes it to the remote branch as well. Now A will have to push his changes as well as Pull changes made by B.

So what will A do in this case ?

like image 774
Akshay Barge Avatar asked Oct 31 '25 15:10

Akshay Barge


2 Answers

In this case, A should pull B's changes down first, make sure everything works, commit, and push.

Generally we (my team) don't work quite like that.

When we have two developers working closely on a feature, we work on separate branches and merge into a shared feature branch.

Among the advantages of this is that you can commit and push on your own schedule, which means that you can make your code work without worrying about the other developer's changes and your code makes it to the server quicker. That is, it's somewhere other than your own machine, somewhere that's probably backed up.

like image 93
GregHNZ Avatar answered Nov 03 '25 07:11

GregHNZ


A must git pull first (some merge may be needed) and than push the code.

If A try to push his code in the first place, git will tell that the remote and local branches have diverged and instruct the developer to pull the code first.

If you pay attention to git commit error messages (and git status messages) you will always know what to do.

like image 30
aeliton Avatar answered Nov 03 '25 07:11

aeliton