Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push local Git branch to origin

Tags:

git

I'm working on two machines and origin repo on third one (origin is accessible from the other two, no direct connection between machine1 and machine2).

# Machine 1 $ git branch   master * testing   cms  # Machine 2 $ git branch * master 

Now, I want to push the testing branch to the origin and have it on machine2 too, so the final effect would be:

# Machine 2 $ git branch * testing   master 

I have tried:

# Machine 1 $ git push origin testing  # Machine 2 $ git pull origin testing                # bunch of merge conflicts $ git checkout -b testing origin/testing # errors too 

Current state is:

# Machine 1 $ git branch -r   origin/HEAD -> origin/master   origin/master   origin/testing 

How to do it?

My next question probably will be: how to delete the origin/testing branch?

like image 252
takeshin Avatar asked Jun 24 '10 11:06

takeshin


People also ask

How do I push a branch with another name?

You will usually push your local branch to a remote branch of the same name—but not always. To push to a branch of a different name, you just need to specify the branch you want to push and the name of the branch you want to push to separated by a colon (:).

Does git push push all local branches?

No, git push only pushes commits from current local branch to remote branch that you specified in command.


2 Answers

Instead of using git pull (which fetches and merges), try git fetch (which won't try to merge with your current branch on machine2, and cause conflicts):

# Machine 1 $ git push origin testing  # Machine 2 $ git fetch origin testing $ git checkout -b testing origin/testing 
like image 118
Bruno Avatar answered Sep 19 '22 09:09

Bruno


You have successfully pushed the testing branch to origin so now you just need to get the branch to machine2.

Not sure of the state of teh repo on machine2 so I would delete the directory (Or create a new one to use) and just clone the repo on Machine2 and checkout testing ...

So on Machine2 in an empty dir (new or clean):

$ git clone git@github/somewhere $ git branch * master  $ git checkout testing # ... # something about getting and switching # ...   $ git branch * testing  master 
like image 31
abarr Avatar answered Sep 20 '22 09:09

abarr