Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

In Mercurial you can close a branch like this: hg commit --close-branch, this means the the branch will not be listed anymore but will still exist, and can still be listed if you use hg branches --closed

I have learned that in Git generally branches are not kept, they disappear, specially when doing fast-forward merges.

So my question is: can you keep branches in git but in a way that you don't list them anymore?

Edit: Some additional context: In Mercurial branches are metadata, so each commit always knows it's branch. In Mercurial if you want to delete a branch, you strip the base branch revision. You can also rebase and end up with the same result as with Git. Mercurial Bookmarks are pointers, so they have the exact same behavior than a Git Branch.

share|improve this question
1  
Branches in Git never "disappear", and remain available until they are deleted. As far as I know there is no "closed" state for branches. But since branches are just a pointer to a commit, you can copy the branch name and commit id to an archive file if you like. –  Greg Hewgill Jun 6 '13 at 5:47

3 Answers 3

up vote 8 down vote accepted

I know it's not exactly the same, but could you use a workflow where you tag the feature branches before ‘closing’ them?

For example:

git merge feature-wxyz -m "Merge message"
git tag closed-feature-wxyz feature-wxyz
git branch -d feature-wxyz

Of course, you could also annotate the tag (git tag -a closed-feature-wxyz -m "Description of closed branch" feature-wxyz) if you wish.

I know it's not exactly what you asked for, but this would satisfy:

  1. a record of the branch is kept
  2. the branch is no longer visible in git branch
  3. you can still base a new branch on the closed one: git checkout -b new-feature-ghij closed-feature-wxyz
share|improve this answer

If you just want to merge a branch while still keeping a record of it's existence, you could always tell git not to fast-forward the merge using git merge --no-ff this will create a new commit with two parents, and a commit message along the lines of "Merged [branch_name] into master"

Since git allows you to check out any commit and make a branch from it, you could always look for the merge commit and re-create the branch if you need it. As others have stated, using git tag can make finding these easier.

If you're not merging the branch, then you need to get more creative. MY first idea would be to add a new remote called archive, and push the branches you're tired at looking at into it.

$ git init --bare ../archive.git
$ git remote add archive ../archive.git
$ git push archive feature_branch
$ git branch -D feature_branch
$ git branch -r
    origin/master
    archive/feature_branch

this thread suggests using git update-ref to move the branch somewhere git won't look for it, but that's messing a bit too much with the git internals for my liking.

share|improve this answer

I'm not aware of this feature directly but as in git tag and branch is essentially the same except for the latter not being a head, if you create a tag and remove he branch, IMO you get the same behavior. Unless I misunderstood the real goal.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.