tkleczek
tkleczek

Reputation: 338

Is there a way to shorten branch names in git commands?

When I work on a bigger project, I use long branch names, eg. dev/username/PROJECT-JIRANUM_some_description. It would be cool to be able to do sth like this:

git branch -D STH(xxxx)

Where STH() is some syntax that would use some glob-like matching of branch names (so that xxxx could be a JIRA number contained in branch name). If there is ambiguity, git would inform and abort the command.

It sth like this is possible at the moment? I could not find any information on this.

Upvotes: 3

Views: 1536

Answers (3)

Ashutosh Jindal
Ashutosh Jindal

Reputation: 18869

I would recommend using zsh with prezto since it gives you branch name completion as follows: ('...' appears every time I press tab for branch name completion)

enter image description here

If you go down this route, for reference here is the list of prezto modules I've enabled (in ~/.zpreztorc):

# Set the Prezto modules to load (browse modules).
# The order matters.
zstyle ':prezto:load' pmodule \
  'environment' \
  'terminal' \
  'editor' \
  'history' \
  'archive' \
  'directory' \
  'spectrum' \
  'utility' \
  'completion' \
  'ssh' \
  'git' \
  'history-substring-search' \
  'prompt'

I believe the important ones (for what you need) are utility, completion and git

Upvotes: 2

user3159253
user3159253

Reputation: 17455

Since git branches are actually movable labels, locally you may name them as you wish. The only actual need is to follow your project conventions when you push your changes back to a central repo. For your convenience you may configure branch specific fetch- and push- settings (check those branch.<name>.... settings) to automatically map your branch on fetch, merge and push.

Upvotes: 0

NaN
NaN

Reputation: 8601

My advise is to rename you branches to something that is short and easy to remember for you git branch -m <oldname> <newname>.

Otherwise you should enable git-completion, if do not already have. See git http://code-worrier.com/blog/autocomplete-git/. This way you can simply use Tab to auto complete your branch names.

Upvotes: 0

Related Questions