r/git • u/Kackboy • Nov 05 '21
Is git and bash the "same"?
Hello!
I've got a 'under the hood' type of question about git. Hope I make sense and that its not too stupid of a question.
So when working with git theres these commands that do different type of actions, like git add, git commit and so on. Are these commands using bash underneath, or how does it work? Is git a shell in itself?
Hope I make sense!
Edit: Thank you all!
6
u/Grodesby Nov 05 '21
You call git using bash, but git is a C application that does not itself run bash, but manipulates the file system directly using C.
2
u/ergotofwhy Nov 05 '21
git is a command that runs on a command line. The underlying terminal could be bash, or it could be zsh, gnome-terminal, or windows cmd.
the easiest way to think of this is that git is an executable program itself, and the commands are arguments that get passed to the program
3
u/RhoOfFeh trunk biased Nov 05 '21
git is just a command-line program. It accepts the parameters provided and does its thing.
bash, or zsh, or CMD, or whatever terminal emulator you use is simply offering you a way to run (and maybe stitch together) command-line programs, like git, grep, cat, or thousands of others.
My guess is that you downloaded "Git Bash", which is a very useful CMD replacement for windows that makes interacting with git a bit nicer thanks to default settings and utility programs. I do use it myself when on a Windows machine and find it a useful tool.
5
u/fourhundredthecat Nov 05 '21
terminal emulator
you might be confusing shell with terminal emulator
2
u/RhoOfFeh trunk biased Nov 05 '21
There's not that much difference from my POV. Just because we don't use ANSI escape sequences to address the 80x24 display doesn't mean it's not a teletype terminal.
So read 'or whatever terminal emulator you use' as an addition to the list, not a substitution for it.
7
u/arienh4 Nov 05 '21
Eh, there's a pretty massive difference. A terminal emulator is something that, well, emulates a terminal. The linux console is a terminal emulator, as is screen/tmux, and graphical ones like rxvt, xterm, Alacritty, PuTTY.
A shell is an interface that runs inside a terminal that allows you to interact with the system. That's your bash/zsh/CMD, but also Gnome, KDE, Windows Shell.
They're certainly not interchangeable.
-1
u/RhoOfFeh trunk biased Nov 05 '21
I thought I was pedantic.
I also thought I had addressed this concern with my second sentence. Yes, there's a difference. But does that matter for this discussion?
1
1
u/3rdRealm Nov 09 '21
Running, for example, git status, runs the same thing on bash, fish, zsh, sh, and every other shell as long as it is not aliased to something else and git is in the shell path. Git itself is a C program that gets called when git is run in the terminal.
1
u/christian-mann Nov 05 '21
I think I understand your question. Git was originally implemented as a pile of shell scripts, which used programs like ls, mkdir, cp, sha1sum, et cetera, to do the job of tracking content. Since then the core functionality has been rewritten to be actual compiled binary programs, written in C, that use the actual operating system APIs. For example, this is git-diff: https://github.com/git/git/blob/master/diff.c
However, some functionality is still implemented in terms of shell scripts, such as git-filter-branch: https://github.com/git/git/blob/master/git-filter-branch.sh
0
u/JonnyRocks Nov 06 '21
git is an application. i am guessing you are young and dont have a lot of CLI experience. but before graphic user interfaces we used command line. got is the program and add is an argument. so a commandline calculator might take. calc add 3 5 and reply with 8
11
u/Isvara Nov 05 '21
A shell is a program that lets a user run other programs, usually just by typing their name. So a shell will offer a prompt and receive input like
git add. It breaks it up into pieces, looks at the first part and says, "I don't know what this is, so it must be a program on disk," then runs the program typically at/usr/bin/git, telling it, "Hey, you were called using the command linegit add". Then git looks at that command line and decides what it needs to do.So no, git is not a shell, but it is commonly launched by one. Git doesn't care what launched it: popular shells are bash, zsh and fish.