开发者

Git deleting a remote branch that's not in remotes/origin

开发者 https://www.devze.com 2023-03-28 22:01 出处:网络
I had a remote branch called new_auth. I wanted a new remote branch to track that remote branch, so I did the following:

I had a remote branch called new_auth. I wanted a new remote branch to track that remote branch, so I did the following:

git-remote add -t n开发者_开发技巧ew_auth -m new_auth pivot git@github.com:myco/my_project.git/my_project

Now when I do a git branch -a, I see:

* master
  new_auth
  remotes/origin/HEAD -> origin/master
  remotes/origin/new_auth
  remotes/pivot/HEAD -> pivot/new_auth

I'd like to delete this remotes/pivot/HEAD -> pivot/new_auth. I've tried:

git push pivot :new_auth
git branch -rd pivot/new_auth
git remote rm pivot
git remote rm pivot/new_auth

No luck. Any ideas?


Your remotes/pivot/HEAD was created because you gave the -m option to git remote add (the command will not automatically create the symref if you leave out -m new_auth).

A similar symref is created when you clone a repository. If a remote repository has a HEAD ref/symref, your clone of it will end up with refs/remotes/origin/HEAD pointing to one of the remote-tracking branches corresponding to the remote branch pointed to by HEAD in the remote repository.

These symrefs let you refer to the “default branch” of a remote by just using the remote’s name (e.g. pivot “expands”1 to refs/remotes/pivot/HEAD, which points to refs/remotes/pivot/new_auth).

You can delete the symref with this command:

git remote set-head pivot -d

1 See the <refname> entry of Specifying Revisions in gitrevisions(7).


Overall, I am not really clear about what you were trying to accomplish with the git remote add command. If pivot and origin actually point to the same remote repository (same “Git URL”), then there should be no need for an additional remote. If you just want origin/new_auth to be the “upstream” branch for your local new_auth branch, then you can arrange that with

git branch --set-upstream new_auth origin/new_auth

(this can also be done with git push -u if you already have something ready to push). Once the upstream branch has been configured, you can use a bare git pull to automatically pull from origin/new_auth when you have new_auth checked out (you might also want to git config push.default upstream so that git push will only push to the upstream branch instead of pushing all branch names that exist in both your local and the remote repositories).


Try this:

git push remotes/pivot/HEAD :new_auth

or

git push remotes/pivot :new_auth
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号