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.
Push a new Git branch to a remote repo Clone the remote Git repo locally. Create a new branch with the branch, switch or checkout commands. Perform a git push with the –set-upstream option to set the remote repo for the new branch. Continue to perform Git commits locally on the new branch.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With