Skip to main content

Getting Started with Git


Using Git with Command Line

To start using Git, we are first going to open up our Command shell.

  • For Windows, you can use Git bash, which comes included in Git for Windows.
  • For macOS and Linux you can use the built-in terminal.

The first thing we need to do, is to check if Git is properly installed. Once you've opened your terminal application, type git version. The output will either tell you which version of Git is installed, or it will alert you that git is an unknown command. It should show something like git version X.Y if Git is installed.

Example:

git version

After successfully executing the above command you will get an output similar to the one shown below:

git version 2.31.1

Customize Git Environment

Your Identity

The first thing you should do when you install Git is to set your user name and email address. This is important because every Git commit uses this information, and it’s immutably baked into the commits you start creating:

git config --global user.name "gitopia"
git config --global user.email [email protected]

Again, you need to do this only once if you pass the --global option, because then Git will always use that information for anything you do on that system. If you want to override this with a different name or email address for specific projects, you can run the command without the --global option when you’re in that project.

Your Editor

By default, Git uses the system default editor, which is taken from the VISUAL or EDITOR environment variable. We can configure a different one by using git config.

git config --global core.editor vim

Checking Your Settings

To verify your Git settings of the local repository, use git config –list command as given below.

git config --list

The above command will produce the following result.

user.name=gitopia
[email protected]
color.status=auto
color.branch=auto
core.editor=vim

Creating Git Folder

Now, let's create a new folder for our project:

mkdir hello-world
cd hello-world
  • mkdir makes a new directory.
  • cd changes the current working directory.

Now that we are in the correct directory. We can start by initializing Git!


Initialize Git

Once you have navigated to the correct folder, you can initialize Git on that folder:

mkdir hello-world
cd hello-world
git init

After successfully executing the above commands you will get an output similar to the one shown below:

Initialized empty Git repository in /Users/gitopia/hello-world/.git/

You just created your first Git Repository!