In this article we will be focusing on some advanced Git commands which you will be using frequently while you are working with Git.
First, you need to install Git on your computer. Follow these instructions if you have not done that already. Once you have Git installed, we can move on to advance Git commands.
How to install Git on Linux
Most of the Linux distributions comes up with Git as pre-installed. Even if it is already there, it’s good to update it to the latest version.
sudo yum install git
Note: For this article we are using Red Hat Enterprise Linux, you can find the step by step installation instructions form here.
If you are on a Debian based distribution like Ubuntu, try the following command to install it.
sudo apt-get install git
For openSUSE, use the following command:
sudo zypper install git-core git
For more different Linux distributions, there are instructions for installing on this link.
Now, you have successfully installed Git on your Linux system. Here are the top essential Git commands that will help in your day-to-day tasks.
The simple examples will give you an understanding of the commands, so you can easily remember the syntax when you need to use them.
Note: If you are new to command line then you should first brush-up your skills to comfortable with command line in Linux terminal by reading this article.
#1 git config
In Git you can specify user identity by providing its “Username” and “Email address.” This information will be used during each commit operation. Execute below command in terminal to assign identity:
git config –global user.name “your_GitHub_username”
git config –global user.email “your_GitHub_email id”
But for some reason if you want to keep your email private then follow the instructions in this article. You only need to check two boxes in your GitHub account to achieve it.
Now that your identity is set up, you can configure the default text editor that will be used when Git needs you to type in a message. If not configured, Git uses your system’s default editor.
Also Read : How to install Visual Studio Code on Linux
For Ex: For this article we are using Visual Studio Code as our default editor. If you want to set it as default editor for you too then type below command in Git bash:
git config –global core.editor “code –wait”
Note: –wait option will wait for the Visual Studio Code window to be closed before returning control to the command line.
Note: – You can open Visual Studio Code from terminal by typing “Code . “
This setting configures compression level to be used. Valid range for compression is -1 to 9.
-1 value indicates zlib compression and is default compression level. 0 value means no compression, and 1 to 9 are various speed/size tradeoffs, 9 being slowest.
git config –global core.compression 2
This setting configures diff viewer tool. For example, below command configures vscode as a diff tool:
git config –global diff.tool vscode
Note: We have used –global option everywhere, which will make this configuration global.
It means that same configuration will be applied to all repositories present on current system. To make configuration repository specific just remove –global option.
To list Git configuration execute below command in terminal:
git config –list