I'm working on a fairly large git repo with a couple of thousand (remote) branches. I am used to using auto-completion (using [TAB]) in the console (Git Bash in that case), so I unconsciously do that for git commands, too.
e.g. I'd type
git checkout task[TAB]
with the effect that the console stalls for often minutes. Is there a way to limit auto-completion to local branches only?
git fetch --all and git pull -all will only track the remote branches and track local branches that track remote branches respectively. Run this command only if there are remote branches on the server which are untracked by your local branches. Thus, you can fetch all git branches.
It can really save you a lot of typing. If there is more than one possibility, then it will let you know that it needs more information and you can type a little bit more of the word and try again. Git auto-completion is a separate script, and it's included inside the Git source code repository on GitHub.
To view your remote branches, simply pass the -r flag to the git branch command. You can inspect remote branches with the usual git checkout and git log commands. If you approve the changes a remote branch contains, you can merge it into a local branch with a normal git merge .
You don't need refs/remotes here. git checkout -b dev origin/dev will work fine. This will always work: git checkout -b newlocaldev --track origin/dev . If you want the local branch has the same name as the remote one, and the remote one doesn't have a tricky name, you can omit the -b newlocaldev .
With Git 2.13 (Q2 2017), you can disable (some of) the branch completion.
git checkout --no-guess ... # or: export GIT_COMPLETION_CHECKOUT_NO_GUESS=1
See commit 60e71bb (21 Apr 2017) by Jeff King (peff
).
(Merged by Junio C Hamano -- gitster
-- in commit b439747, 01 May 2017)
As documented in contrib/completion/git-completion.bash
now:
You can set the following environment variables to influence the behavior of the completion routines:
GIT_COMPLETION_CHECKOUT_NO_GUESS
When set to "1", do not include "DWIM" suggestions in
git-checkout
completion (e.g., completing "foo" when "origin/foo" exists).
Note: DWIM is short for Do What I Mean, where a system attempts to anticipate what users intend to do, correcting trivial errors automatically rather than blindly executing users' explicit but potentially incorrect inputs.
completion
: optionally disable checkout DWIMWhen we complete branch names for "
git checkout
", we also complete remote branch names that could trigger the DWIM behavior. Depending on your workflow and project, this can be either convenient or annoying.For instance, my clone of
gitster.git
contains 74 local "jk/*
" branches, but origin contains another 147.
When I want to checkout a local branch but can't quite remember the name, tab completion shows me 251 entries. And worse, for a topic that has been picked up for pu, the upstream branch name is likely to be similar to mine, leading to a high probability that I pick the wrong one and accidentally create a new branch.
Note: "picked up for pu": see a What's cooking in git.git
: it starts with:
Commits prefixed with '
-
' are only in 'pu
' (proposed updates) while commits prefixed with '+
' are in 'next
'.
This is part of the Git Workflow Graduation process.
pu
(proposed updates) is an integration branch for things that are not quite ready for inclusion yet
This patch adds a way for the user to tell the completion code not to include DWIM suggestions for checkout.
This can already be done by typing:git checkout --no-guess jk/<TAB>
but that's rather cumbersome.
The downside, of course, is that you no longer get completion support when you do want to invoke the DWIM behavior.
But depending on your workflow, that may not be a big loss (for instance, in git.git I am much more likely to want to detach, so I'd type "git checkout origin/jk/<TAB>
" anyway).
I'm assuming that you are using the git-completion.bash
script, and that you only care about git checkout
.
To accomplish this, I just changed one line in the definition of the _git_checkout ()
function in git-completion.bash
:
< __gitcomp_nl "$(__git_refs '' $track)" --- > __gitcomp_nl "$(__git_heads '' $track)"
My understanding is that this only affects the tab-completion action (because of its location within the *
case of the switch-case statement).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With