Piping output from Git Bash to clipboard

GitClipboardGit Bash

Git Problem Overview


I often need to relay my Git output to my ever-friendly code buddies. The best way I know how is by doing this:

Right-click Git Bash title bar > Edit > Mark > Select lines > Enter

Bam - everything I selected is in my clipboard, and I am filled with joy.

Problem is, that's the boring way, and I like my relationship with Git to be full of excitement and glamour.

In Windows, you can pipe console output to your clipboard like-a so:

C:\> dir | clip

Amazing, right? Well, when you try to do something that in Git Bash, here's what happens:

> git branch | clip
sh.exe": clip: command not found

And that makes me sad. Is there a way to pipe Git Bash output to my clipboard in Windows so I can once again be filled with joy?

Git Solutions


Solution 1 - Git

Well, actualy git branch | clip works fine for me. clip command just calls clip.exe from C:\Windows\System32\. Make sure you have clip.exe installed somewhere in your PATH.

Solution 2 - Git

copy thing.txt to clipboard

cat thing > /dev/clipboard

Put contents of clipboard into thing.txt

cat /dev/clipboard > thing.txt

I aliased these things to pbcopy and pbpaste so I feel like I'm on my mac.

Solution 3 - Git

@madhead's answer is correct - the PATH variable must be set from within git-bash. Here's an elaboration on how to fix this issue, courtesy of Cairnarvon's answer on superuser:

To check what PATH is currently set to:

> echo $PATH

And to set it, assuming a 64-bit architecture:

> export PATH="$PATH:/c/Windows/System32:/c/Windows/SysWOW64"

Result of git branch | clip:

* master
  dev
  dev_foo

Solution 4 - Git

Easiest way to copy Git Bash console's entire content:
Right click anywhere on the console > Select All

Keyboard shortcut for the same: Ctrl+Shift+A
Enable this keyboard shortcut by enabling Options > Keys > Ctrl+Shift+letter shortcuts.

mintty version: 3.4.4 (x86_64-pc-mysys) [Windows 19042]

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBucketView Question on Stackoverflow
Solution 1 - GitmadheadView Answer on Stackoverflow
Solution 2 - Gitj03mView Answer on Stackoverflow
Solution 3 - GitBucketView Answer on Stackoverflow
Solution 4 - GitArun Kumar BView Answer on Stackoverflow