For some reason,
whenever I want to run a git command and use tab completion to achieve something like :
$git checkout master
When I press tab after writing git checkTab, something hello -n is being written automatically, so it results in
$git checkhello -n
I can't use git CLI with tab completion because of this. Does anyone know what's going on here?
Checked my aliases in .bashrc, one of the alias had the term 'hello' echoed in it. Removing it solved the problem.
Related
I'd like to be able to occasionally use a different editor when writing commit messages. I've found plenty of answers on how to change the default editor, but I don't want to change that - VIM is normally fine. What I'd like is some option like git commit --editor=<editor_name> where <editor_name> is the editor I want to use when writing the commit message for that commit only.
The only thing I've found that is similar to what I'd like is opening a new file with <editor_name> <newcommitfilename>, write message, save and close file, then use git commit -F <newcommitfilename>.
Is there an easier way to achieve this?
Thanks!
All Git commands use the form:
git <verb>
You may insert options before the verb, e.g.,
git -c core.pager=cat show
The -c option in particular takes a configuration item name, such as core.pager, core.editor, user.name, and so on, and a value, joined with an equals sign = like this.
Since your goal is to use a particular editor, git -c core.editor=whatever commit does the trick.
As several commenters noted, there are other ways to do this. For the editor in particular, the environment variable $GIT_EDITOR overrides core.editor, so:
GIT_EDITOR=nano git commit
runs git commit with GIT_EDTIOR set to nano for the duration of the one command (assuming POSIX-style shell).
I often find myself appending --help|less to commands that I am crafting a command in a shell to explore the CLI of the program I am using. What ways are there to accomplish the same thing with fewer key-presses?
For instance, if I wanted to use the new way of switching branches (I don't, I'm stuck in my ways happily doing git checkout -b other_branch) then my history (and thought process) could look like
git change other_branch # Guess what the command should be
git --help|less # Backtrack to where I am confident I know the command and ask for help
git switch --help|less # Gradually build up the command from there
git switch other_branch
For context:
I typically want the pager either to be able to search or because I am working in tmux and activating scrolling takes a few additional, and awkward, key-presses.
I typically use zsh on Ubuntu or Debian.
I typically use arrow up to iterate on my previous command.
Add the following to your .zshrc file:
# Alt-H: Open `man` page of current command.
unalias run-help
autoload -Uz run-help{,-{git,ip,openssl,p4,sudo,svk,svn}}
Then restart your shell.
Now, whenever you're in the middle of typing a command, you can press AltH (^[h) to immediately open the man page for that command. Then, after you quit your pager, Zsh will will automatically restore your command line, so you can finish typing.
So, I have reproduced it. Running:git ls-files|grep navbar.html|xargs vim
in my Git Bash and exiting vim making my Git Bash not accept keyboard inputs anymore. However my other Git Bash windows working fine.Any ideas how can I get arround this problem?
If you execute reset, it will be fixed.
This is a common vim usage error (see also https://unix.stackexchange.com/questions/77395/grep-l-xargs-vim-generates-a-warning-why). This command will do what you want:
git ls-files | grep navbar.html | xargs sh -c 'vim "$#" <$0' /dev/tty
Sometimes like when you are not on full screen and you insert command like
git log | git diff
or something like them that need a bigger window size to show bunch of data you'll get colon sign
:
that is for displaying data summary and you can scroll data to see more by using arrow keys.
at the end you can quit this mode using q key
press "Q" keyword to exit.
I'm using Github and Git bash on my Windows PC (running XP).
On Ubuuntu I'm happyily using git grep to plough through my code, but every time I call something like:
git grep "some text in my repo"
on Windows I get the results and afterwards I'm stuck with the bash window showing all kind of things [END], ~, [RETURN]... whenever I try to enter something.
Question:
What else besides CTRL+R, CTRL+Q, FN+END, Q, ESC can I try to not having to force-close and reopen git:bash in order to continue to work.
Thanks!
EDIT:
This is what I mean:
As soon as I start typing, the [END] string re-appears (or 50 lines ~) and I cannot write any command on Git, because whatever is in the way swallows half of what I'm typing.... nice description...
I was wondering about this also after installing git and running git bash. It seems "git grep" pipes commands through "less".
Solution: Just type q.
Is git launching less (or something similar) so up/down arrows on your keyboard scrolls through the matches? If you don't want that, try the instructions from https://stackoverflow.com/a/12166923/972216:
set GIT_PAGER=cat
Would disable it for your console session once, or
git config --global core.pager cat
to disable it for your account.
first time poster.
This came up in conversation at work this week...
Is there a way, when you connect to git remotely that you can get display current working directory/current git repo/branch in your terminal prompt?
Apparently, there are linux/vim scripts that exist for linux users, and I'd like to add this sort of shell script to my profile.
Currently I'm using some info from this page http://sos.blog-city.com/mac_os_x__bash_customize_your_terminal_prompt_a_little_color.htm to address some of this info locally.
Thanks in advance.
Get a copy of the git completion script. You can get this from git itself, or if you have a Linux box handy you could even just copy it from there (it'll probably be /etc/bash_completion.d/git). Then, arrange for this to get "sourced" by bash. You can do this by adding something like this to your .bashrc:
. /usr/local/git-completion
(assuming you named the file /usr/local/git-completion on your Mac).
Finally, you'll want to adjust your prompt. Also in your .bashrc, add something like:
export PS1='[\w$(__git_ps1 "|%s")]\$ '
Here's a blog post (not by me) that talks about this (and some other related stuff) in more detail: http://blog.bitfluent.com/post/27983389/git-utilities-you-cant-live-without
OK, I experimented with this after you pointed me in the right direction, my google searches got more refined results.
A lot of people point to the post you shared with me, like here: https://superuser.com/questions/31744/how-to-get-git-completion-bash-to-work-on-mac-os-x but I found some other jewels like these, which I didn't use but were informative: jeetworks.org/node/10 , jonmaddox.com/2008/03/13/show-your-git-branch-name-in-your-prompt/ .
I needed some different guidance on installing git.completion because I use homebrew which I found here: https://github.com/bobthecow/git-flow-completion/wiki/Install-Bash-git-completion which covers several ways to install it.
Finally, my bash/terminal has been a bit pokey so I upgraded to the latest bash with these instructions before I meshed with any of this: milkbox.net/brace_completion_snow_leopard_upgrading_bash/ and got some great speed improvement.
I ended up having to rebuild my profile script very carefully but with trail and error (because of differences between Bash 3 and 4, and some syntax errors)- now it looks great, and does the job.
Thanks again.
Sorry about above the security restraints of the site, restrict me (since I'm a newb) to 2 links to combat spam.
You just need 2 steps to do it.
Step.1:
Open ~/.bash_profile in your favorite editor and add the following content to the bottom.
For me it is like
emacs ~/.bash_profile
Step.2:
Add the following content to the bottom.
function git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'}
export PS1='\h:\w$(git_branch) \u\$'
Done!
P.s:
If you want your terminal colorful, try the following content.
export PS1 = '\[\e[1;39m\]\h:\w\[\e[01;39m\]$(git_branch) \[\e[01;39m\]$ \[\e[0m\]'
Another option to get git branch/status info in your shell prompt is to use powerline-shell.
You can see what this looks like in this screenshot:
The magenta/green bar is the current branch name. Its color indicates whether the working directory is clean. There are also markers that appear when there are untracked files, or when there are commits to be pulled-from/pushed-to the upstream remote.
Powerline-shell is compatible with bash, zsh, and fish.