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

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.

  • git move locally committed changes to the new branch and push
  • How can I hide the “pr” remote branches?
  • Can't switch branch: untracked working tree file because of case-insensitivity?
  • Git feature branches and minor code improvements
  • Git branch naming to show parent branch
  • Workflow to “backport” change into different Mercurial (Hg) branch?
  • Jenkins + Git Publisher - How to push back to {GIT_BRANCH}?
  • remove .gitignore from the staging
  • Git couldn't find remote ref for a tag or commit hash
  • Can I customize the web.config transform for appharbor deployment?
  • git stash pop vs git rebase
  • How to retrieve the history of a file?
  • One Solution collect form web for “How to close a branch WITHOUT removing it from history in git?”

    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
    Git Baby is a git and github fan, let's start git clone.