112

Is there any command in Git, that clear the screen. for example in window command line after execute a lot of code, if you type cls, then it will clear all the previous code. so i want the same type of functionality in Git. so can anybody will tell me the command name.

John Y
  • 14,123
  • 2
  • 48
  • 72
naresh kumar
  • 2,165
  • 3
  • 19
  • 21

10 Answers10

188

Actually you are looking for a Unix user environment command

clear

or you can use the keyboard shortcut

ctrl+l

http://en.wikipedia.org/wiki/Clear_(Unix)

To clear entire command history in Git Bash.

history -c
JoSSte
  • 2,953
  • 6
  • 34
  • 54
leoshtika
  • 2,038
  • 1
  • 13
  • 10
  • 1
    Works under Windows, if you are running GIT Extensions (http://code.google.com/p/gitextensions/) and run a GIT Bash prompt. – Contango Jan 14 '14 at 11:11
  • 3
    should have been able to come up with that, gave up after clr – Zac May 22 '14 at 19:40
  • 7
    It does not work, it only moves everything up. It does not help to look through output lines after cleaning. – Yevgeniy Afanasyev Jun 14 '16 at 05:14
  • 9
    You might prefer to use `reset` so it gets rid of the buffer as well. See [this answer](http://superuser.com/a/123185) – Daniel J.G. Nov 07 '16 at 16:48
  • 2
    When using `clear` multiple times, I've found that it only allows me to scroll back to the previous `clear`. Is that the usual effect? If so, is there a command that does `scroll-up-so-that-the-next-command-is-the-only-one-I-can-see-but-the-history-is-still-preserved-if-I-want-to-scroll-up-to-it?`. PS Prize for most hyphenated string? ;) – ro͢binmckenzie Oct 03 '17 at 16:53
  • This works, if you do ``history -c``` then clear everything is gone – samarmohan Oct 26 '20 at 20:00
52

try using reset command, it will absolutely clean your screen but you will still have access to previous commands

reset
Abhijeet Ahuja
  • 5,596
  • 5
  • 42
  • 50
  • 5
    Nice! `clear` command simply moves your scrollbar in a fashion that you see a clear screen in front of you. So if you scroll up you can still see the output of the commands you had fired previously. `reset` command resets the screen scrollbar and flushes the output of all previous commands as well. So we can say `clear` command is soft clean and `reset` is hard clean :) – RBT Mar 23 '17 at 01:28
  • 1
    `reset` command reinitializes the terminal, as if it was reopened from scratch. – RBT Mar 23 '17 at 01:30
  • 1
    One way in which `reset` is **not** like reopening from scratch is that your current directory is retained. Also, the command history that gets carried over when you open a new Git Bash terminal completely from scratch is... somewhat wonky, particularly if you've opened several instances, closed *some* of them, then opened yet more new ones. If you do `reset`, then you know that the command history *in that particular instance* is still there. So yeah, `reset` is *exactly* what you want in most situations, and much better than "from scratch". – John Y Feb 22 '22 at 14:38
  • 1
    To put it simply: `reset` in Git Bash is the closest thing to `cls` in a Windows command prompt, which is what the question is asking for. So this is a much better answer than `clear`. – John Y Feb 22 '22 at 14:52
9

Neither clear nor history -c does the work actually.
Scroll up, all commands will be visible.

Solution:
If you are in Windows 10, and using mintty 2.7.9 (or above ?) for git bash, use Alt + F8 ... this will work.
Best of luck.
Happy coding.

Reference: here (Perhaps it didn't work for Windows 7)

Surajit Biswas
  • 779
  • 7
  • 25
8

Neither clear nor history -c was clearing the history permanently.
All commands will be visible when scrolled up.
So, I solved the issue by:

In my instance the path for bash history was:
/c/Users/<your_username>/.bash_history

I removed the file by the following commands:

rm ~/.bash_history

After that, I restarted the terminal. the commands were gone.

Alon Kogan
  • 3,258
  • 1
  • 21
  • 20
Sushan Yadav
  • 111
  • 2
  • 4
7

CTRL + L

search for more shortcuts in: here

eldias1978
  • 79
  • 1
  • 2
4

Another option is modify (or create in your user folder) your .bash_profile and add this:

alias cls='clear';

With this you can clear the bash with a 'Windows' command.

Cristian Batista
  • 283
  • 3
  • 17
2

At the moment I use

clear;reset;clear

(in one line) and it sort of works (git version 2.32.0.windows.1).

18446744073709551615
  • 16,368
  • 4
  • 94
  • 127
0

Most times clr, clear and cls doesn't work use ctrl c to continue writing commands

0

If you are using windows 10 or above version then you can use the command

clear
-4

use clear only without git command

" clear "

Ganesha
  • 3
  • 3