0

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.

6
  • 1
    Did you see this post containing ressource for beginner? Mar 22, 2018 at 8:00
  • And particularly this link about merge Mar 22, 2018 at 8: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? Mar 22, 2018 at 8:04
  • The Tag Info Page might also be helpful.
    – kowsky
    Mar 22, 2018 at 8:15
  • Thank you, I will look at those resources.
    – Robbie
    Mar 22, 2018 at 8:21

2 Answers 2

0

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  
2
  • So when a pull is performed, in this case D and G are merged into M?
    – Robbie
    Mar 22, 2018 at 17:51
  • 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, 2018 at 1:37
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.