Just trying to learn about setting up source control with bitbucket and sourcetree for a project I'm working on in a group. I can set up a repository and push the project to it, but I'm confused about what happens when someone else tries to push their update. If someone's trying to push a new update and they first perform a pull, what exactly does that do to their update? Does it take the last push and merge it with their last commit? Also, is merging usually only done with separate branches or do you merge branches with themselves if there is a conflict? Been researching this for hours and I'm just having trouble wrapping my head around it.
-
1Did you see [this post](https://stackoverflow.com/q/315911/3729797) containing ressource for beginner? – Julien Rousé Mar 22 '18 at 08:00
-
And particularly [this link](https://www.sbf5.com/~cduan/technical/git/git-3.shtml) about merge – Julien Rousé Mar 22 '18 at 08:02
-
You should review a tutorial, but when you `git pull` it either makes a new commit (merge strategy) or replays your unique commits on top a new base from the remote (rebase strategy). You don't "lose" your work at all. I have never heard of someone merging a branch into itself; what would be the point of that? – Tim Biegeleisen Mar 22 '18 at 08:04
-
The [Tag Info Page](https://stackoverflow.com/tags/git/info) might also be helpful. – kowsky Mar 22 '18 at 08:15
-
Thank you, I will look at those resources. – Robbie Mar 22 '18 at 08:21
-
@Robbie Have you get the answer which helps you solve the question. If yes, you can mark the answer (`√` symbol on the left of the answer). And it will also benefit others who have similar questions. – Marina Liu Mar 28 '18 at 08:16
2 Answers
To directly answer the changes git take when executing git pull
before git push
, please refer below steps:
If a developer committed changes on the local repo, while other developers pushed their changes to remote repo during the period. Then the commit history will look as below (local repo has commits C
and D
which are not pushed, remote repo has E
, F
and G
which are not exist in local repo):
…---A---B---C---D master
\
E---F---G origin/master
So the developer need to do git pull
(or use the command git fetch
and git merge
) before push the local changes to remote:
git pull origin master
# Input merge comment (if there has confilcts, need to resolve conflicts firstly)
Then the commit history will be:
…---A---B---C---D---M master
\ /
E---F---G origin/master
And after pushing to remote repo (git push origin master
), the commit history will be:
…---A---B---C---D---M master, origin/master
\ /
E---F---G

- 36,876
- 5
- 61
- 74
-
-
Yes, un-pulled commit(s) from remote repo and un-pushed commit(s) from local repo will perform as merge when you execute `git pull`. – Marina Liu Mar 23 '18 at 01:37
I suggest you to always pull your branche with the rebase option.
As alreay said a git pull
will process a git merge between your two branches
git pull origin master
… C---D--------M master
/ /
---A---B---E---F---G origin/master
but if you use the rebase option
git pull --rebase origin master
it will remove your commit from local branch, update it and reapply your local commit after the origin/master update (whitout the merge commit M
)
… C---D master
/
---A---B---E---F---G origin/master
So its flatten your history and make it easier to read.

- 61
- 6