A Beginner’s guide to GIT

Chandani Mourya
6 min readMar 27, 2021

Hey there looking for a GIT tutorial which doesn’t make you scratch your head? Here’s the beginner’s guide to GIT. So let’s get our hands dirty with git.

Photo by Cookie the Pom on Unsplash

What is Git?

GIT simply acts as a time machine for your code in technical terms “Git is a distributed version control system for tracking changes in source code during software development.”

It takes series of snapshots of your project. With Git, every time you commit (save the state of your project) Git basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot. So that you may go back later if required.

So let’s begin with downloading Git on your computer

Here’s the link to download Git according to your Operating System:

After downloading, follow the steps mentioned here for installing GIT on your Desktop.

On the website you will find an E-book (ProGit) which covers detailed explanation of everything about git.

Here’s the link to the book:

If you prefer videos over text based tutorials, than here’s the link for videos:

So let’s begin with GIT

Note: This article is meant to get you started with Git and GitHub for the first time, so sometimes, I have mentioned the most basic or most used version of a command so that users would easily understand it and get started.

Let’s get started…

After installation if you want to know which version of git is installed on your desktop just type the following command :

git --version
git — version
git — version

it will show the current version of GIT installed on your desktop

After Git is successfully installed on your desktop, set your username and email address

git config --global user.name "some user name"

git config --global user.email someemail@email.com

For further commands, we may need a Folder

So at a convenient location on your computer, create a folder named “git_test” (You can also name it according to your preference).

Open this git_test folder and create a new file. You can create any file but I’m creating an HTML file so that the guide could help beginner web developers.

I’ve created an index.html file in this folder (index.html is simply your homepage/first page you visit on website) add some basic HTML code to the file.

Basic HTML code

For using the GIT commands first open the git_test folder in your command prompt window/terminal.

To use Git in a folder we would first need to initialize a GIT repository inside the folder( A repository is basically a storage location, similar to a folder)

For Initializing the folder as a git repository :

git init

This command creates a Git repository. This is required for using further Git commands.

git init

Checking your git repository status:

git status

It will check the git repository status. The details of files inside it, changes that need to be committed (committing is basically saving the changes) and details of branch we’re working on.

git status

Telling GIT about updates to files or new files:

git add .

It basically tells git about updates in your file or about new files added in current folder. Contrary to it’s name it doesn’t add files to your repository.

git add .

Let’s check the status of our folder now.

git status

To commit/save our updated files on git repository :

git commit –m "Some Message"

This command records changes to our git repository. The “snapshot” of your repository is taken here.

As a developer it is always suggested to keep the message meaningful (and not something like “Updated some code”).

git commit

If you want to check details of previous commits:

git log

This command will show full details of previous commits.

git log

In case you want to see fewer details then add the — oneline option.

git log --oneline
git log — oneline

Well now that you have made a GIT repository, let’s create an online repository on GitHub (You can also do this on BitBucket)

Steps:

  • Head to GitHub and in the upper-right corner of any page, click + and then click New repository
New repository
  • Type a name for your repository
Repository name
  • Write an optional (message) or description if you want. You can make the repository either public or private. Public repositories are visible to everyone on Github, while private repositories are only visible to you.
public or private repository
  • We would skip this optional step as we will be importing an existing GIT repository, so let’s click on “Create repository”.
Create repository

Since we will be pushing contents from an existing repository so we will use the following commands

Github commands
  1. Connect your local git repository to remote repository:
Git remote add origin <repository URL>

2. Set Branch:

git branch -M main

A branch in git is similar to the branch of a tree, we could create multiple branches of a repository so that many people can work on the same code at the same time without getting confused.

3. Push your commits to online repository:

git push –u origin main

Here we push(upload) all the content from our local repository to the remote repository on Github.

Reference links :

Link to the Github Repository created in this article:

https://github.com/ChandaniM/git__test

Thank you for reading my article, I hope you enjoyed it and learnt something from it. I would be more than happy if you send feedback or suggestions.

You can find me on:

LinkedIn: https://www.linkedin.com/in/chandani-mourya-8069a1198/

GitHub: https://github.com/ChandaniM

SoloLearn: https://www.sololearn.com/profile/6578118

--

--