32

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?

takeshin
  • 49,108
  • 32
  • 120
  • 164
  • Unfortunately, this question is missing information on what kind of errors that you were getting when trying to `git checkout -b testing origin/testing`. Also, you don't explain if you want to delete the `testing` branch on the remote repo, or if you just want to delete the remote-tracking branch `origin/testing` locally. –  Jun 24 '14 at 01:03

4 Answers4

24

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
Bruno
  • 119,590
  • 31
  • 270
  • 376
16

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
abarr
  • 1,140
  • 3
  • 13
  • 28
1

The original poster states:

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

You have to be clear what you mean by that, because after you push testing to the remote repo, there will also be a local remote-tracking branch called origin/testing that keeps track of the last known status of the testing branch on the remote. You can find this remote-tracking branch under .git/refs/remotes/origin/.

Deleting both the remote testing and local origin/testing branches

If you delete the branch on the remote with the following commands:

git push origin :testing
# Or
git push origin --delete testing

then the local remote-tracking branch origin/testing will also be deleted for you automatically.

Deleting just the local origin/testing branch

If for some reason you just wanted to delete the local remote-tracking branch origin/testing, but not the testing branch on the remote, then you can run the git branch -d command with the --remotes or -r flag:

git branch --delete --remotes origin/testing
# Or shorter
git branch -dr origin/testing

If you get an error message that the branch can't be deleted because it hasn't been merged yet, then you can force the deletion by using the -D flag instead of --delete or -d.

See Also

Community
  • 1
  • 1
1

All you have to do is the following:

On Machine 1, deploy the remote branch and link the local testing branch to it:

git push -u origin testing

On Machine 2, deploy a local branch that's linked to the remote testing branch:

git fetch origin && git checkout --track origin/testing

Now both local testing branches must be deployed and linked to the remote testing branch =)

Now for deleting a remote branch you can simply try this :

git push origin --delete testing

or

git push origin :testing
Loukan ElKadi
  • 2,687
  • 1
  • 16
  • 20