Reputation: 105
We have colleagueA and colleagueB. Both download code from a GitHub repository and start to modify it, lets say app.py. Each one modifies different parts of the code in his own computer.
What is good git practice when merging both app.py into the final one to push it to the original repository?
I'm new to GitHub, I'd like simple answers if possible.
Upvotes: 1
Views: 685
Reputation: 1323953
If you are both pushing to the same branch (for example master), then the second one to push (say developerB) will fail, as in here, with:
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and merge the remote changes
hint: (e.g. 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
In that case, I recommend a git stash + git pull --rebase
which will:
origin/master
branch (with developerA app.py
modificationsorigin/master
(you can automate that git stash + git rebase process with a bit of configuration: see "Can “git pull
” automatically stash and pop pending changes?")
If there are any merge conflicts, they will be resolved locally, on developerB's workstation, with local compilation and tests to validate that developerB's changes are working with what developerA has pushed.
Once the rebase is completed, a simple git push
form developerB will work (assuming that developerA has not pushed again on the common branch)
You can avoid that of course by pushing to a dedicated branch for each developer, but you will need to reconcile those parallel development at some point.
At least, with the workflow I describe above, if both developers are participating to the same development effort, that reconciliation will be sooner rathen than later.
Upvotes: 1