I am using Git to manage the development and releases of some software used internally by my company, and having not used Git much prior to joining this company, am still learning how to use it/ best practice when using it for version management, feature development, etc.
I have reached the point where my local Git repository is now quite cluttered with several branches- I have been creating a new branch for the development of each feature/ fixing of each bug raised, merging that branch with master
once the feature is complete/ bug is fixed, and pushing master
to the server. The server only has the one branch, master
running on it.
I want to 'clean up' my local repository, so that old development branches that I am no longer using no longer show up when I run git branch
, or other such commands. But still want to have access to the old branches in case I need to revert/ checkout any old working versions/ compare them to the current version if something breaks, etc
I came across this question on SO: How can I archive git branches?, which, as I understand, indicates that I can 'clean up' my local repository by archiving and deleting the old branches. But I'm a bit hesitant to do this before clearing up a few things that I'm unsure about:
If, when I run git branch
, I have the following branches on my repository:
master
testFeature
brokenTestFeature
FixedTestFeature
and I want to 'archive' the testFeature
& brokenTestFeature
branches, as I understand, I would run:
git tag archive/testFeature testFeature
git tag archive/brokenTestFeature brokenTestFeature
git branch -d testFeature
git branch -d brokenTestFeature
After doing this, if I then run git branch
again, the output should display:
master
FixedTestFeature
and if I wanted to checkout testFeature
again, I could run:
git checkout -b testFeature archive/testFeature
and the testFeature
branch would then be displayed again the next time I ran git branch
, with all of its commit history, etc still intact?
If I archived a number of branches, how would I display all of the branches that I have archived, so that I know what branches I have in the archive to checkout
if/ when I decide that I need to?