1

I have created a new branch on git, and using git branch, I get put into this interactive window, with (END) at the end (see picture). Is this a program like less or more? enter image description here

I would like to print out the contents of this program onto the actual command line, rather than this interactive app. I know that its not stdin, stdout or stderr.

PS: I am sure there is answer for this already, but I cannot seem to phrase the question to get answers.

Ben Butterworth
  • 22,056
  • 10
  • 114
  • 167
  • That screenshot looks like it's the VSCode built-in terminal (based on the tab selections at the top) - did you run `git branch` from within the editor? – UnholySheep Dec 21 '19 at 23:16
  • I ran it from the integrated terminal in vscode (on mac), so its still the z-shell. I have tried it in a normal terminal window and on a different operating system (Ubuntu), it does the same thing. – Ben Butterworth Dec 21 '19 at 23:21
  • This seems to be a Visual Studio thing, not a command-line Git thing - but it may be the case that VS is running command-line Git, which sends its output to a pager. **If** that's the case, you can perhaps control the pager from within Git. – torek Dec 21 '19 at 23:25
  • I have also used the normal mac terminal (without vscode), and also SSH'd into an Ubuntu machine. It has nothing to do with visual studio or vscode anymore. I got the same thing using the z-shell and bash. I have updated the photo too. – Ben Butterworth Dec 21 '19 at 23:30
  • It has something to do with Z-shell or Oh-my-zsh. When I SSH'd into a machine without Z-shell, it worked fine. However, just switching from z-shell to bash on my mac, using `/bin/bash` **did not work.** – Ben Butterworth Dec 21 '19 at 23:36
  • 3
    it looks like `less`. Try pressing the letter `h` on you keyboard and if you're directed to a `help` screen, then you know it is `less`. Something like `producer_program | less` ? But How or why that is happening I can't help with. Good luck. – shellter Dec 22 '19 at 00:10
  • 2
    @shellter `git` often automatically calls `less` when it needs a pager and `vim` when it needs an editor. Both can be configured, they're just the default. – phd Dec 22 '19 at 00:28
  • @phd : Right you are! To flesh out the search a little further for the OP, I'll note that in a typical *nix environment, it would be the value of `$PAGER` so could replace `$PAGER` value with `cat` or `more` (traditionally ;-) ). Good luck to all! – shellter Dec 22 '19 at 19:54

1 Answers1

3

That's a pager, probably less by the looks of it. It switches away from the shell by sending a "terminal initialization" string to the terminal, then outputs there.

To have it print inline you can skip the pager:

git --no-pager branch

or use the LESS environment variable (on Linux at least - not sure about Mac):

LESS=FRX git branch

Where F = quit if the output fits on one screen, R = print colours, and X = don't send the terminal initialization string.


To make Git always skip the pager for branch, use this:

git config --global pager.branch false

Source


I asked a related question on Ask Ubuntu, and you might find more useful info there: How does "less" switch to the text, then back to the prompt?

wjandrea
  • 28,235
  • 9
  • 60
  • 81