3

I've done something incredibily stupid. I figured I should ask before I tried to "fix" it and accidentally make things worse.

I tried to list all remote branches in my git repo:

git branch remote

Obviously this isn't the correct command. Instead of listing remote branches, I created a local branch called remote. I should have done:

git branch -r

Can I just remove this branch with:

git branch -d remote

Will this have any effect on my remote branches? I don't want to accidentally delete anything on the remote side.

3
  • 2
    No, that command will only delete the local branch with that name, so you're safe. Happy gitting :-) Commented Apr 10, 2013 at 19:47
  • 1
    That should be safe, as @cbuckley says. Additionally, if you really want to be paranoid about it, git update-ref -d refs/heads/remote is a bit more explicit (as remote branches reside under refs/remotes/<remotename>/<branchname>, while local branches are under refs/heads/<branchname>). Commented Apr 10, 2013 at 20:07
  • 2
    Not incredibly stupid. Just a normal mistake. :-) Commented Apr 10, 2013 at 20:35

2 Answers 2

3

Yes,

git branch -d remote

Take a look:

MYHOST:git wwheeler$ cd seiso/
MYHOST:seiso wwheeler$ git branch
* master
  trunk
MYHOST:seiso wwheeler$ git branch remote
MYHOST:seiso wwheeler$ git branch
* master
  remote
  trunk
MYHOST:seiso wwheeler$ git branch -d remote
Deleted branch remote (was 15dc59f).
MYHOST:seiso wwheeler$ git branch
* master
  trunk
MYHOST:seiso wwheeler$ 
Sign up to request clarification or add additional context in comments.

Comments

2

I have made that mistake too. One easy thing to do is rm .git/refs/heads/remote.

Much of the git repository structure is straightforward, and you can learn a lot by poking around in it.

1 Comment

Reading @twalberg 's comment above kept me from asking "well is .git/refs/heads/remote the remote repo or my branch called remote"? Thanks for the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.