git push to remote branch

拟墨画扇 提交于 2019-12-18 09:56:10

问题


Folks,

I had cloned a repo. I created a branch out of it to work on a feature by issuing the following command:

git branch fix78

then I worked on that branch by

git checkout fix78

I continued to make commits to this local branch. Now I wanted to push this to the repo and hence I issued the following command:

git push origin master:fix78

I viewed the repo from a web browser and saw that a new branch called fix78 was created on the repo. But it did not have any of my commits that I had made.

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

There is a repo(master(trunk in the SVN lingo)), now when I am working on a feature I want to create a local branch of it and then I also want to check in this branch to the repo(so that other team members can see what I am working on), then I want my local branch to be in sync with this remote branch that I create.

Any help/feedback would be totally awesome.

Thanks.


回答1:


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

You can fix it by doing git push origin :fix78 to delete the remote branch and then git push origin fix78 to push your local branch to the remote repo.




回答2:


The push command has the form of

git push remote_name source_ref:destination_ref

All you need to do to correct your error is

git push origin +fix78:fix78

The plus indicates that you don't care about that branch potentially losing history as the previous push was an error.

Alternate syntax is

git push -f origin fix78

if you omit the destination, it's implied that it's the same name. If tracking is set up to a particular branch on the remote it will go to that one. Deleting branches has 2 syntaxes, the old:

git push -f origin :fix78

and

git push --delete origin fix78

The first is read as "push nothing into fix78" which deletes it.

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

git push . origin/master:master

will update master without having to checkout master.

Hope this helps



来源:https://stackoverflow.com/questions/6279082/git-push-to-remote-branch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!