Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close a branch WITHOUT removing it from history in git?

Tags:

git

branch

I'd like to make a commit and close its branch, without removing it from history.

With mercurial I'd commit --close-branch, then update to a previous one, and go on working. With git... I'm confused.

like image 511
o0'. Avatar asked Apr 20 '12 08:04

o0'.


People also ask

How do I close a specific branch in git?

Delete a branch with git branch -d <branch> . The -d option will delete the branch only if it has already been pushed and merged with the remote branch. Use -D instead if you want to force the branch to be deleted, even if it hasn't been pushed or merged yet.

Does deleting a branch remove it from history?

Like all deletes in svn, the branch is never really deleted, it's just removed from the current tree.

Can you archive a branch?

There will be a archive option for each branch, beside the delete option for the branch. A user selecting that will get prompted to be sure they want to archive the branch. Archiving the branch will result in the branch only showing on a new Archived tab on the branches page.

Should you close git branches?

They're unnecessary. In most cases, branches, especially branches that were related to a pull request that has since been accepted, serve no purpose. They're clutter. They don't add any significant technical overhead, but they make it more difficult for humans to work with lists of branches in the repository.


1 Answers

There's no exact equivalent to closing a branch in Git, because Git branches are more lightweight than in Mercurial. Their Mercurial equivalent is more bookmarks than branches.

If I understand correctly, closing a branch in Mercurial roughly makes it disappear from the branch list, so you can achieve the same thing by archiving it. A usual practice is to tag its tip as archive, and delete it:

git tag archive/<branchname> <branchname> git branch -d <branchname> git checkout master 

The branch will be deleted, and can be retrieved later by checking out the tag, and recreating the branch:

git checkout archive/<branchname> git checkout -b new_branch_name 
like image 199
CharlesB Avatar answered Oct 07 '22 04:10

CharlesB