Quote from the question (emphasis added):
This worked well for a while but my workspace is getting a bit cluttered now. Is there anyway of saving a branch somewhere so it can be recovered, but so that its not in the normal workspace (as if its been deleted)?
What do you mean by "my workspace is getting a big cluttered now"? Do you just mean that git branch
shows too much stuff you don't want to see all the time, such as your backup branches which begin with _
?
If that's the case, I don't like the other solutions. The cleanest, simplest, and least storage-intensive solution by far I think is to just write your own version of git branch
, called git branch_
which wraps around the regular git branch
but doesn't show your backup branches beginning with _
.
Here's how to do that:
- Create
git-branch_
in ~/bin
:
mkdir -p ~/bin
gedit ~/bin/git-branch_
- Now put this into it
#!/bin/bash
# Ignore (don't print with `git branch_`) branch names which begin with
# these prefix strings
PREFIX1="z-"
PREFIX2="_"
git branch --color=always "$@" \
| grep --color=never -v "^ $PREFIX1" \
| grep --color=never -v "^ $PREFIX2"
- Now close and re-open your terminal, and/or log out and log back in if this is the first time creating and using the
~/bin
directory (so that Ubuntu can auto-add the ~/bin
dir to your path via your ~/.profile
file). Then run the following:
# 1. show ALL branches
git branch
# 2. show all branches EXCEPT those whose names begin with `z-` or `_`.
git branch_
That's it! Note that I like to prefix my backup branch names with z-bak/some_name
, hence why I've also excluded branch names which begin with z-
.
Since git branch_
is a wrapper around git branch
, and passes all arguments to it with "$@"
, you can use ANY and all parameters/options to git branch_
as you can to the regular git branch
.
Example: these commands are the same:
git branch -h
git branch_ -h
Get this git branch_
script in my repo here: https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles/blob/master/useful_scripts/git-branch_.sh. See the comments inside of it as well.