Git clicking on a remote branch

People,

I cloned a repo. I created a branch from it to work on the function by issuing the following command:

git branch fix78

then I worked on this branch on

git checkout fix78

I continued to commit this local branch. Now I wanted to push this to the repo, and so I issued the following command:

git push origin master:fix78

I looked through the repo from a web browser and saw that a new branch called fix78 was created on the repo. But I did not have any of my obligations that I made.

What am I doing wrong here? This is what I am trying to achieve:

There is a repo (master (trunk in SVN lingo)), now when I work on a function, I want to create a local branch, and then I also want to check this branch on the repo (so that other team members can see what I'm working on) then I want my local branch to synchronize with this remote branch that I create.

Any help / feedback would be absolutely awesome.

Thank.

+46
git git-branch git-remote version-control git-push
Jun 08 '11 at 13:00
source share
2 answers

git push origin master:fix78 pushes the local master to a remote branch named fix78. You wanted to push the local fix78 branch, which has the same syntax, but without master:

You can fix this by running git push origin :fix78 to remove the remote branch, and then git push origin fix78 to redirect the local branch to the remote repo.

+60
Jun 08 2018-11-11T00:
source share

The push command has the form

 git push remote_name source_ref:destination_ref 

All you have to do to fix your mistake is

 git push origin +fix78:fix78 

Plus indicates that you do not care that the branch is potentially losing history, since the previous click was an error.

Alternative syntax

 git push -f origin fix78 

if you omit the destination, this implies that it is the same name. If tracking is configured for a specific branch on the remote control, it will go on to that. Removing branches has 2 syntaxes, the old one:

 git push -f origin :fix78 

and

 git push --delete origin fix78 

The first reads as "push anything in fix78", which removes it.

One trick is that if you specify . as a remote name, this implies the current repo as a remote. This is useful for updating a local branch without having to check it:

 git push . origin/master:master 

The wizard will update without a control wizard.

Hope this helps

+51
Jun 08 2018-11-11T00:
source share



All Articles