harunB10
harunB10

Reputation: 5207

Git - Push changes from two local machines to master

I have changes on two different machines and they are different to each other. How can I push them to remote origin/master without having conflicts.

I have this:

Local machine 1: changes A, B
Local machine 2: changes C

How can I push them to remote master and then pull back to both machines so I can have:

Local machine 1: changes A, B, C
Local machine 2: changes A, B, C

Upvotes: 1

Views: 112

Answers (2)

Gauthier
Gauthier

Reputation: 41955

If you have remote access to the repo on machine 2, assuming all changes are commited (A, B, and C are existing commits):

on machine 1:

  • fetch and merge the changes from machine 2: git checkout master && git pull machine2 master (I'm assuming you have committed to master on both machines, it sounded like that)
  • if you get conflicts, solve them and go on to produce the merge commit
  • optionally verify that all functionality implemented in A, B, and C, works on machine 1
  • push the merge commit to your remote: git push origin master

on machine 2:

  • refresh your master: git pull origin master

"Without having conflicts" is not possible if the changes in A, B, and C change the same things. Git does an amazing job at solving conflicts that are solvable, if it does not want to do it for you in that case you have to look into it personally.

Upvotes: 1

Pau Trepat
Pau Trepat

Reputation: 717

If the changes hasn't conflicts between them it not exists any problem to get this history.

From machine 1:

git push --set-upstream origin master

And then in machine 2:

git pull --rebase

If you execute git pull without --rebase your will have a merge commit in your history getting this:

Local machine X: changes A, B, Merge-commit, C

Upvotes: 1

Related Questions