Next: , Previous: , Up: Top   [Contents][Index]


7 Keeping Your Repo Organized

There are a few commands you should know about to help keep your local repo clean.

Removing old branches

Developers add branches to the Savannah repo and when development on them is done, they get merged into master. Then the branches on Savannah are deleted (as shown in General practices).

However, your local copies of those branches (labelled with the ‘origin/’ prefix) remain in your local repo. If you don’t need them, then you can clean up your repo as follows.

First, remove any related tracking branch you may have:

$ git pull                                Get up to date
$ git branch -d feature/merged-feature    Remove tracking branch

Then, ask Git to clean things up for you:

$ git fetch --prune                       Remove unneeded branches
Removing cruft

As Git works, occasional “cruft” collects in the repository. Git does occasionally clean this out on its own, but if you’re concerned about disk usage, you can do so yourself using ‘git gc’ (short for “garbage collect”). For example:

$ du -s .                               Check disk usage
-| 99188   .                            Almost 10 megabytes
$ git gc                                Collect garbage
-| Counting objects: 32114, done.
-| Delta compression using up to 4 threads.
-| Compressing objects: 100% (6370/6370), done.
-| Writing objects: 100% (32114/32114), done.
-| Total 32114 (delta 25655), reused 31525 (delta 25231)
$ du -s .                               Check disk usage again
-| 75168   .                            Down to 7 megabytes
Renaming branches

Occasionally you may want to rename a branch.10 If your branch is local and you are on it, use:

$ git branch -m feature/new-name

Otherwise, use:

$ git branch -m feature/old-name feature/new-name

You then need to fix the upstream repo. This command does so, using an older syntax to simultaneously delete the old name and push the new name. You should be on the new branch:

$ git push origin :feature/old-name feature/new-name

NOTE: It is the leading ‘:’ in the first branch name that causes Git to delete the old name in the upstream repo. Don’t omit it!

Finally, reset the upstream branch for the local branch with the new name:

$ git push -u origin feature/new-name

Footnotes

(10)

This discussion adopted from here.


Next: , Previous: , Up: Top   [Contents][Index]