Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Ground Controller Lvl 1
Message 1 of 2

Conflicts when updating my own branch from different computers

Good afternoon,

I have a problem with git that I can not understand.

 

I have a branch in which I am the only person working and I update it from two different computers.

 

Suppose I create the branch from computer A, make changes and upload them to the remote repository by pushing.

 

The next day, I go to the computer B, I make a fetch to get the branch, I get into it, I work without problems and I push the changes.

 

Now I go back to computer A, I do a fetch and changes are detected (as expected). If I do a status, it tells me that I have changes. I do a git pull and I get conflicts in the files that I modified the first day from the computer A.

 

How is possible have conflicts in my own branch when no commit is pending? I am the only person working on it, should not the files be updated cleanly without conflicts?

 

I have also tried with fetch + merge and the same conflicts happens.

 

I am doing something wrong? Or is git working wrong?

 

Thank you.

1 Reply
Community Manager
Message 2 of 2

Re: Conflicts when updating my own branch from different computers

Let me make sure that I'm understanding what you're describing. It sounds like what you're doing is:

 

  1. You have a git repository centrally stored somewhere (we'll call this initial state `0001` and assume that it includes branch `foo`)
  2. You clone `0001` to computer A and checkout branch `foo`
  3. You clone `0001` to computer B and checkout branch `foo`
  4. On computer A, you change some files
  5. On computer A, you `git add --all .`
  6. On computer A, you `git commit` (creating state `0002`)
  7. On computer A, you `git push` (so that the central repository has state `0002`)
  8. On computer B, you `git pull` (not `git fetch`)
  9. On computer B, you change some files
  10. On computer B, you `git add --all .`
  11. On computer B, you `git commit` (creating state `0003`)
  12. On computer B, you `git push` (so that the central repository has state `0003`)
  13. On computer A, you `git pull` (not `git fetch`)

 

If the above is a summary of the general workflow you. follow, then you shouldn't see any conflicts. If you deviate from this at all, then it is possible to see conflicts. For example, if you use `git fetch` instead of `git pull`, you could see some conflicts because `git fetch` only updates your local repository with new records from the central repository, it doesn't update your working directory.

 

Honestly, there are any number of ways that you could get the end result you're describing if you don't strictly ensure that each computers' local working directory is completely clean at every step. Some examples:

 

  • Add another commit on either computer A or computer B between step 7 and 8
  • Don't use `git add --all .` so there's some new file that didn't get added to what got pushed at some step
  • Using `git fetch` without an immediate `git merge origin/foo` instead of `git pull`

 

Trust me, I occasionally forget to add a file or forget to commit before I push. These kinds of things happen to even git experts from time to time. But as you get used to the natural rhythm of things, it will happen less often.

 

On the other hand, it is possible though not likely at all, that you have found a bug. If you can detail exact steps to reproduce the behavior you're seeing, please share them and we can investigate.

 

I hope that helps!