How can I archive git branches?
git delete branch
git archive specific tag
git close branch
git rename branch
git download zip command line
I have some old branches in my git repository that are no longer under active development. I would like to archive the branches so that they don't show up by default when running
git branch -l -r. I don't want to delete them, because I want to keep the history. How can I do this?
I know that it's possible to create a ref outside of refs/heads. For example,
refs/archive/old_branch. Are there any consequences of doing that?
I believe the proper way to do this is to tag the branch. If you delete the branch after you have tagged it then you've effectively kept the branch around but it won't clutter your branch list.
If you need to go back to the branch just check out the tag. It will effectively restore the branch from the tag.
To archive and delete the branch:
git tag archive/<branchname> <branchname> git branch -d <branchname>
To restore the branch some time later:
git checkout -b <branchname> archive/<branchname>
The history of the branch will be preserved exactly as it was when you tagged it.
How can I archive git branches?, Tag the unwanted branch: git tag archive/sprintjuly2010 sprintjuly2010. Delete the branch: git branch -d sprintjuly2010. Push the branch deletion to origin: Git Archive Summary . Git archive is a helpful utility for creating distributable packages of git repositories. Git archive can target specific refs of a repository and only package the contents of that ref. Git archive has several output formats that can utilize added compression.
Jeremy's answer is correct in principle, but IMHO the commands he specifies are not quite right.
Here's how to archive a branch to a tag without having to checkout the branch (and, therefore, without having to checkout to another branch before you can delete that branch):
> git tag archive/<branchname> <branchname> > git branch -D <branchname>
And here's how to restore a branch:
> git checkout -b <branchname> archive/<branchname>
Procedure to archive git branches. · GitHub, git-archive - Create an archive of files from a named tree Create a tar archive that contains the contents of the latest commit on the current branch, and extract it git archive --format=zip --prefix=git-docs/ HEAD:Documentation/ > git-1.4.0-docs.zip. Put everything in the current head’s Documentation/ directory into git-1.4.0-docs.zip, with the prefix git-docs/. git archive -o latest.zip HEAD. Create a Zip archive that contains the contents of the latest commit on the current branch.
git-archive Documentation, I've been working on a few feature branch that is ready to be merged into master. I like merging them with one commit and not rebasing them Procedure to archive git branches. GitHub Gist: instantly share code, notes, and snippets.
Extending Steve's answer to reflect the changes on the remote, I did
git tag archive/<branchname> <branchname> git branch -D <branchname> git branch -d -r origin/<branchname> git push --tags git push origin :<branchname>
To restore from the remote, see this question.
Archive A Branch In Git Without Losing Any History, , make sure you've changed its settings and consider closing all open issues and pull requests. "My solution was to archive each branch as a tag then remove the branches from Git on my local machine as well as the Git origin server." Note: This post discusses tagging the state of the branch using "git tag" before archiving/deleting the branch.
You could archive the branches in another repository. Not quite as elegant, but I'd say it's a viable alternative.
git push git://yourthing.com/myproject-archive-branches.git yourbranch git branch -d yourbranch
Archiving repositories, The git archive command is a Git command line utility that will create an archive file from specified Git Refs like, commits, branches, or trees. git archive accepts Can I archive or stash a branch? I may be using the wrong terminology but hopefully I'm making sense. I have a branch within BitBucket that has a number of features that I want to keep, but will not be implementing in the foreseeable future - don't ask me, ask marketing.
Git archive, It is also possible to create archives of other items than HEAD , such as branches, commits, tags, and directories. To create an archive of a local branch dev : git The git branch command lets you create, list, rename, and delete branches. It doesn’t let you switch between branches or put a forked history back together again. For this reason, git branch is tightly integrated with the git checkout and git merge commands. Common Options git branch. List all of the branches in your repository.
When should we clean up old, no longer used GIT branches , git checkout -b awesomeFeature Switched to a new branch 'awesomeFeature' $ touch magic $ git add magic $ git commit -m 'add magic' [awesomeFeature The example of showing branches in Git. For our example, I have created a few branches in local as well as remote repositories. Learn how to create local/remote repos/branches. The following commands are used for creating the local branches: $ git branch br-tst1 $ git branch bt-tst2 $ git branch br-tst3. This is followed by creating remote
GIT Tags Guide, Git doesn't natively supported the concept of an archived branch, but the usual way to emulate this is by creating a tag called archive/< These branches are also known as topic branches. Feature branches isolate work in progress from the completed work in the master branch. Git branches are inexpensive to create and maintain. Even small fixes and changes should have their own feature branch. Creating feature branches for all your changes makes reviewing history simple.
- git-rm does not delete resources from the repository, it only removes them from the index kernel.org/pub/software/scm/git/docs/git-rm.html You can easily restore these resources using
git checkout [rev] file
- Not that I know of. I use
Attic/<branchname>lightweight tags to archive branches, though.
- tags are the quick and safe and sane choice.
- I'm a Git newbie, but in trying this, I think the proper command for restoring the branch is:
git checkout -b <branchname> archive/<branchname>
- Is there any reason not to use an object-tag in this case ? Being able to see who archived the branch and when could be interesting.
- @GrégoryJoseph: That's a so-called "annotated tag". And yes, using that can make a lot of sense, I'd say.
- small note, you probably want
branch -Dsince it's likely not to be fully merged if you are archiving it in this way
- Very nice. Here is a complete tutorial with explanations.
- I guess you didnt have enough points yet but it would be better when you do to just edit the existing answer - +1 anyway though :)
- @jkp editing other users' code and commands is usually frowned upon because subtle changes in a git command can do drastically different things, and you might not understand why the original author wrote something the way they did. better to just make your own answer or leave a comment.
- Or even worse than drastically different things, a subtle change in commands or code could lead to subtly different results, which could be really hard to figure out, I would suggest leaving as a comment so that the poster of the answer can edit himself or respond with a counter-claim referencing the potentially different results (Which such counter-claims are rather common)
- Excellent, apart from everyone else on this thread, you actually answered the question.
- You can create
git-bundleinstead of separate repository.
- With newer versions of git (as suggested here), this alias gives completion:
!git tag archive/$1 $1 && git branch -D