Git

How to Use Git Bash

Recently, Git has been widely used among software engineers. It is not only free, but is also open-source. In addition, it’s powerful for its distributed nature, fast operation and branch handling mechanism. The distributed property makes it easy and efficient for multiple developers to work together. And this is very useful for group project. Meanwhile, Git works fast with its lightweight operations. Lastly, every developer can work with the code as its own branch. Others can merge different branches. Thus, this makes cooperation-work quite easy.
 
 
 
 

1. Introduction

In the meanwhile, Bash is a very popular shell. It stands for Bourne Again Shell. A shell is a user interface to access to an operating system’s services. And it’s also called command-line interpreter. Basically, shell could be a connection between engineers and operating system. Specifically, we can use commands to access or modify files in operating systems.

In this article, I’ll introduce how to combine these two together. More specifically, I’ll focus on how to set both up and make them work. Furthermore, we know that in Unix-like OS and MacOS, Bash is the default shell. So in this article, I’ll emphasize on Windows system.

Below, all the operations are in Windows 10 and Git 2.9.2 version.

2. Git Bash installations and settings

First of all, we know that it’s relatively hard to use command in Windows system. This could be painful for software developers. In Windows, there’s a cmd window, which is similar to the terminal in Unix-like system. However, as I mentioned, it does not support commands. For example, the list ls command like below:

Git bad
ls command not supported

However, things could change. We can use the Git bash, which supports both the Git and the bash shell.

2.1 Git Bash installation

Primarily, we need to download the Git. Go to the link of https://git-for-windows.github.io/. Then download it, as shown below:

Git download
Git download

After downloading, you need to install it.

Git installation
Git installation

During the installation, make sure that you check one option – the Git Bash like below:

Git installation 2
Git installation

After successful installation, you can check out the software and find the Git Bash like below:

Windows software
Git in windows

Then click the Git Bash,  and start a bash shell integrated with Git. This could be really awesome to start working on. Here, you might want to check out whether it’s done with command git --version.

$ git --version
git version 2.9.2.windows.1

2.2 Git Bash setting

Next, you need to set up the Git Bash with your Github account. Make sure you have registered one for yourself.

After registration, open the Git Bash window. This is used for setting up the global parameters. In addition, this will connect your local repository with remote repository – Github.

In the Bash, type following command:

$ git config --global user.name "username"

In the quote, replace the username with your real Github user name.

Then, input another command:

$ git config --global user.email "useremail"

Similarly, replace the user email with your real Github email. That’s it, all settings are done!

3. Git Bash usage

3.1 Git Bash in Windows

After the previous installation and settings, you can start working on the real Git project. For example, right now you are able to use the command like in Unix-like system.

Git bash
Git bash

In addition, you can use other popular commands, like cd, mkdir, rm etc. All these commands are supported in Git Bash now. For further commands, you may refer to the link: http://ss64.com/bash/

Meanwhile, Git Bash also supports Git operation. For example, you might want to use git clone to clone a project from Github.

git clone
git clone

Here,  notice that in the command, it’s better to type the whole command, instead of copying. I encountered an error when I was copying the link directly to the bash. It’s like below:

git clone bad
git clone bad

In addition, you can try more Git operations like below:

git command
git command

For additional Git operations, you may refer to one of my previous article. The link is Git tutorial for beginners.

3.1 Git Bash in Mac/Unix

As I mentioned before, bash is the default shell for both MacOS and Unix-like system. You can check this by typing the following command:

WXMs-MacBook-Pro:~ WXM$ echo $SHELL
/bin/bash

Also, you can check all the shells that your OS supports.

WXMs-MacBook-Pro:~ WXM$ cd /bin/
WXMs-MacBook-Pro:bin WXM$ ls
[		df		launchctl	pwd		tcsh
bash		domainname	link		rcp		test
cat		echo		ln		rm		unlink
chmod		ed		ls		rmdir		wait4path
cp		expr		mkdir		sh		zsh
csh		hostname	mv		sleep
date		kill		pax		stty
dd		ksh		ps		sync

And, you can find other shells, like csh, sh, zsh, tcsh etc.

3. Conclusion

In conclusion, Git Bash is very useful for developers to work in Windows environment. This article explained the basic installation and settings for Git Bash. Furthermode, it is also explained  Github configuration. Happy Git:)

Jun Wu

Jun (Steven) Wu is a current Master student in Computer Science & Engineering department of University of Nebraska Lincoln (Lincoln, NE, USA). His current interests focus on Programming Languages (Java, Python), Relational Database (MySQL), NoSQL Database (Apache Cassandra, MongoDB), and Computer Networks.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
Back to top button