-1

Ok I’m new to this. If there is a remote repo and I have cloned it on my mac, when I git pull and someone else has made changes to the master will my changes be overwritten?

What rules followed? In my current experience files that I have not modified are overwritten but I don’t have any experience as to what would happen if files that I have modified and someone else modified have conflicts. Will I be asked to make a decision or will it be overwritten?

Thanks

George Asda
  • 2,119
  • 2
  • 28
  • 54

2 Answers2

0

In case of pull conflict, you will have chance to choose whether you lose your own change or not. Here shows how to resolve it (How to resolve merge conflicts in Git?). But of course you must communicate with the team on this.

It's always best to avoid such conflict. Using branches helps, when working within a group. Here is a great insight: http://nvie.com/posts/a-successful-git-branching-model/

popuptoast
  • 1
  • 1
  • 2
  • I don’t get it. From my experience I’m never asked to choose. My files are updated automatically. What if I didn’t want to accept changes from the master? – George Asda Sep 21 '17 at 07:57
  • If you don't want changes from master, why did you pull in the first place? – 1615903 Sep 21 '17 at 08:05
  • @GeorgeAsda Here mentions about `mergetool` you may want to setup. https://stackoverflow.com/questions/1435754/how-do-i-resolve-a-conflict-after-git-pull Note that `git pull` is `git fetch` plus `git merge`. – popuptoast Sep 21 '17 at 08:09
  • Because I do not know if I want them yet or not. I have to see first. Also it’s good to have a choice. – George Asda Sep 21 '17 at 08:10
  • @GeorgeAsda then what you need is `git fetch`. By `git fetch` you can get commits from others down to your repo, without merging them to your branch. You can check these commits and decide if you are going to merge them. And you can choose which of these commits, some or all, to "merge" into your branch, through `git merge`, `git cherry-pick`, `git rebase`. – ElpieKay Sep 21 '17 at 08:24
  • Thank you ElpieKay! – George Asda Sep 21 '17 at 08:25
0

If there is a remote repo and I have cloned it on my mac, when I git pull and someone else has made changes to the master will my changes be overwritten?

Yes the changes will be added(integerated) on to the local copy of your current branch, if you do the git pull.

What git pull does, you might find plenty of info about that? To keep it short. This add or incorporate the changes from remote repo to your current branch.

git pull = git fetch + git merge FETCH_HEAD

What rules followed? In my current experience files that I have not modified are overwritten but I don’t have any experience as to what would happen if files that I have modified and someone else modified have conflicts. Will I be asked to make a decision or will it be overwritten?

Answer to the second question. Your current branch is not up to date with origin/master when you do the git pull, it will fetch and add all the changes. If you see if there is conflict between the files, you can solve that using several GUI tools. example, vimdiff, kdiff3, meld, diffuse, and so on you can configure that in your mergetool config.

How to resolve git merge conflicts in cli?

danglingpointer
  • 4,708
  • 3
  • 24
  • 42