Easy steps to start using Git

How to use git for beginners.

Sun Apr 16 2023 - 4 min read

Git is a source control system very popular and adopted by many in the industry, is a distributed system and is open source and free to use, you can work disconnected, and it is powerful and easy to use, here we are going to see an overview of how to start using Git.

The most powerful way to use Git is using the Command Line although there are GUI interfaces like Git Gui, GitHub Desktop, Source Tree, Git Kraken, and many others, Git shines using the command line, so it is important to get familiar with the CLI (Command Line Interface).

Installation

Git works on Linux, Mac, and Windows.

Check if you have git installed in your machine running this command.

foo@pop-os:~$ git --version

If you don’t have it, download Git, also use an editor of your choice, it can be Visual Studio Code, or any other of your preference.

I will be using a Linux OS distribution called Pop!_OS that is build on Ubuntu, so let’s dive in.

Configuration

The first thing to do after having installed Git is to configure it, use your name, and email, and check that the changes were made.

foo@pop-os:~$ git config --global user.name "Your name"

foo@pop-os:~$ git config --global user.email "youremail@host.com"

foo@pop-os:~$ git config --list

Fundamentals

In a distributed source control system, everyone would have the entire project and full history on their machine, this makes it possible to work offline, and no dependence on a central repository, is normal to have GitHub as a central repository for our projects, so everyone can push and pull from there.

The 3 states of Git

  1. Committed - The data is stored locally.
  2. Modified - The file has a change.
  3. Staged - The modified file is part of the next commit snapshot.

The 3 areas of Git

  1. Working directory - Content is created, modified, and deleted.
  2. Staging area - Where changes from the local directory will be staged before being committed.
  3. Git repository - Local git directory.

The is a 4th area to have in a central place that we can call the Remote repository, which could be GitHub.

Git flow

All interactions with git from the command line start with git.

For configuration as we did before.

foo@pop-os:~$ git config

Initialize a git local repository.

foo@pop-os:~$ git init

or

foo@pop-os:~$ git init [ project name ]

Download a repository from remote.

foo@pop-os:~$ git clone [ repository ]

Prepare a file or files in the staging area.

foo@pop-os:~$ git add .

or

foo@pop-os:~$ git add [ file or files ]

Commit a file to the local repository.

foo@pop-os:~$ git commit -m "Message to go with the commit here"

Example

And that’s it, now you know the basics of working with Git, keep practicing and play with this concepts.

Aditional content

Regresar

Enjoy this note? Feel free to share!

X logo Y Combinator logo LinkedIn logo