Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

So many unused branches. How to cleanup?

Tags:

git

I have the following branches:

* master
newbranch
remotes/origin/HEAD -> origin/master
remotes/origin/api-notes
remotes/origin/event-creation-validation
remotes/origin/master
remotes/origin/organizerlocation-bug-demo
remotes/origin/ticket-180
  1. Is the current branch master different from origin/master or are these branches working together?

  2. How can I detect the last changes in the different branches and how can I delete them to cleanup?

Thank you very much.

like image 205
Sandor Farkas Avatar asked Jan 17 '13 15:01

Sandor Farkas


2 Answers

You do not have any reason to worry or cleanup anything. This is why:

Is the current branch master different from origin/master or are these branches working together?

If you created master as tracking branch or if you cloned it (by default clone creates tracking master), then yes, sort of. Tracking simply means that git will use this branch mapping as a default target for push and for merge. It will also display status messages like "branch master is ahead of origin/master by 2 commits".

How can I detect the last changes in the different branches?

I would simply use

git branch -av

This shows short commit id and short summary for all branches, local and remote.

On top of this, you may want to use git log . git log --decorate is very helpful to see which branches point to what commits. In most recent git versions (1.7.11+) you can enable it permanently using this command:

git config --global log.decorate short

How can I delete them to cleanup?

You don't - remote branches are not yours. Remote branches simply reflect state of remote at a time last git fetch was performed. You cannot create them, and even if you remove them using git branch -rd, when next time you do git fetch these remote branch pointers will be immediately back.

But if you completely remove this remote:

git remote rm origin

then all remote branches for this remote will be gone at once.

like image 58
mvp Avatar answered Nov 16 '22 01:11

mvp


1/ Is the current branch master different from origin/master or are these branches working together?

It is different (even if it started from origin/master after the clone), and is not tracking origin/master (see "how do I change the remote a git branch is tracking?").

2/ how can I delete them to cleanup

You can delete a branch from the remotes namespace with:

git branch -rd origin/api-notes

(More at "How do you Remove an Invalid Remote Branch Reference from Git?")

You can git diff or git log two branches to see the commits you don't have:
See "Git diff .. ? What's the difference between having .. and no dots?".
See also "Git: Compare All Local Commits to Remote Repo Version".

like image 32
VonC Avatar answered Nov 16 '22 03:11

VonC