-2

My question is very basic but still it is unclear for me. I am working on a rails project with multiple developers. All of them can pull or push the project. So let me explain my scenario. If I am making changes in my code for the first time and the other developers are also making changes, when I try to push the project I am able to do so. But the other developer face problem in pulling the project. After that If they are able to make changes and pull the project then I am unable to push the project or pull the project. This is how we push the project first:

git add .
git commit .
git pull origin master 

but the error comes warning: Cannot merge binary files or I get the error git pull fails with “Untracked working tree file 'blah' would be overwritten by merge

Mustaghees
  • 506
  • 6
  • 16
Aniket Tiwari
  • 3,561
  • 4
  • 21
  • 61

2 Answers2

1

The problem is coming because you and your friend doing changes on the same line of the file and git is unable to decide which one to take. So in this case its better to go for stash first to save your code. The code will be:-

git stash   :-  To save your code 

git pull    :-  To pull the code from git

git stash apply  :-  To merge your changes with the pulled files, if any merging error is coming then it will hit an error saying merge-conflict,you have to resolve that manually.

git add  :- To add the files

git commit -m "Commit message"  :- To commit it

git push  :-  To push to the repo.

I think this will solve your problem

Yogesh Jangra
  • 66
  • 1
  • 12
0

git checkout accepts --ours or --theirs options for cases like this. So if you have a merge conflict, and you know you just want the file from the branch you are merging in, you can do:

$ git checkout --theirs -- path/to/conflicted-file.txt

to use that version of the file. Likewise, if you know you want your version (not the one being merged in) you can use

$ git checkout --ours -- path/to/conflicted-file.txt

ref:Resolving a Git conflict with binary files

In your case the file is 'blah' in the working directory of remote location. so u can keep one of them.

Community
  • 1
  • 1
Somangshu Goswami
  • 1,098
  • 11
  • 27