How do i remove the "HEAD" branch from the branches list on the left side in SourceTree?

I've tried to right click on it... but there are different options than in other branches... how do I remove this one?

6 answers

1 accepted

Hi Jose,

Here's an extract from the docs:

set-head

Sets or deletes the default branch (i.e. the target of the symbolic-ref refs/remotes/<name>/HEAD) for the named remote. Having a default branch for a remote is not required, but allows the name of the remote to be specified in lieu of a specific branch. For example, if the default branch for origin is set to master, then origin may be specified wherever you would normally specify origin/master.

With -d, the symbolic ref refs/remotes/<name>/HEAD is deleted.

With -a, the remote is queried to determine its HEAD, then the symbolic-ref refs/remotes/<name>/HEAD is set to the same branch. e.g., if the remote HEAD is pointed at next, "git remote set-head origin -a" will set the symbolic-ref refs/remotes/origin/HEAD to refs/remotes/origin/next. This will only work if refs/remotes/origin/next already exists; if not it must be fetched first.

Use <branch> to set the symbolic-ref refs/remotes/<name>/HEAD explicitly. e.g., "git remote set-head origin master" will set the symbolic-ref refs/remotes/origin/HEAD to refs/remotes/origin/master. This will only work if refs/remotes/origin/master already exists; if not it must be fetched first.

I've made the command bold, and it's saying in the paragraph eariler that you use "-d" to delete that symbolic ref. So you're saying the remote ref HEAD should be deleted. However, in my local test case there is no remote branch HEAD so technically this command wouldn't work. It's a local branch here and not a remote one. This can be seen within SourceTree itself quite easily in the sidebar if you expand origin, so deleting the remote ref won't do anything.

So, if HEAD branch is only local then you'd need to use

git branch -D HEAD

...but please make sure you back your repository up first to make sure you're not losing any changes from this. Technically you shouldn't as it's only a branch pointer to the HEAD commit if you've checked something out, but as I say, it's not doing any harm being there.

Cheers

git branch -D HEAD

works.

Hi Jose,

HEAD is a pointer to a commit (usually master) so when you checkout your repository the commit which HEAD points at will be checked out. Usually you'd want it if when checking out you want a different branch or tag to be checked out.

You can take a look at what it's pointing out by issuing the following command:

git branch -r

And you'll probably see something like the following:

origin/HEAD -&gt; origin/master

You can delete HEAD if you don't need it (although it doesn't do any harm being there) by issuing the following command:

git remote set-head origin -d

Hope that helps

Thanks for your help I really appreciate it, but I'm afraid it didn't work... I opened Terminal from the icon next to the git flow icon on the top, and I entered: git remote set-head origin -d But apparently it didn't remove the branch (I did restart SourceTree)... am I doing something wrong?

Thanks for your help I really appreciate it, but I'm afraid it didn't work... I opened Terminal from the icon next to the git flow icon on the top, and I entered: git remote set-head origin -d But apparently it didn't remove the branch (I did restart SourceTree)... am I doing something wrong?

Deleting origin/HEAD from the terminal worked great for me. So glad to not see it anymore.

It would be nice if SourceTree has an option to hide origin/HEAD from the history. And I would have that option be on by default.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

1,770 views 1 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you