Can you close branches in Git?

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.

1

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

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.

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.

No, because a branch in Git is just a label for a single commit that can be changed/removed at will. It’s really what a bookmark is in Mercurial. Git doesn’t have named branches.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật