Ynv
Ynv

Reputation: 1964

Is there a short way of addressing branches in Git?

Is there a shorter way of referring to branches other than typing out their full name?

How would it, for example, look when used with the git checkout command?

To better understand the problem I'm having imagine a repository with around 50 branches with names such as:

/feature/SOMECONSTANT-789738-And-a-very-long-description-copied-from-the-ticket-title

Such branch names are generated by tools like Atlassian Stash. One way of solving this would be local branches with my own short names.

I was wondering if there is another, simpler way of doing it. For example, every local branch could have a number associated with it that one could use to refer to it?

Upvotes: 2

Views: 171

Answers (3)

Rog
Rog

Reputation: 4085

Yes! Well, kind of. Git has command line completion that works for a number of shells, so you only have to type the start of your branch name to find and complete it, without throwing away the context that a long branch name allows.

An aside, we've had requests for the ability to better customise the branch name created from JIRA issues, and it's something we're considering.

Upvotes: 1

CodeWizard
CodeWizard

Reputation: 142074

you can do the following: create any branch name you wish and set it to track any remote branch with the long name.

for example:

git checkout short_name
git branch -u upstream/long_branch_name
// or
git branch --set-upstream-to=upstream/long_branch_name

Both of the later command will do the same. simply different syntax for the same thing.

Upvotes: 3

poke
poke

Reputation: 387637

You can just rename your local branch for your own sanity:

git branch -m feature/SOMECONSTANT-789738-And-a-very-long-description-copied-from-the-ticket-title f/short-branch

This won’t affect the remote branch, and if you have been tracking your remote branch, you can still use git push to push to that long name.

Upvotes: 4

Related Questions