Quick Guide to Git

Basics of Git for beginners

Adil Khan
Adil Khan
May 8 · 4 min read

You can use this article to revise and copy-paste the git commands quickly if there’s a need. This article is For the beginner, By a beginner, and to the beginner.

What is Git

Git is the coolest thing when it comes to tracking changes in any set of files, coordinating work among programmers during software development. Developers rely on Git for version control.

What is Version Control?

Version control, also known as source control, is the practice of tracking and managing changes to software code. It records changes to a file or set of files over time so that you can recall specific versions later.

Git is a Distributed Version Control System. So Git does not necessarily rely on a central server to store all the versions of a project’s files. Instead, every user “clones” a copy of a repository (a collection of files) and has the full history of the project on their own hard drive. This clone has all of the metadata of the original alongside the original, which is stored on a self-hosted server or a third-party hosting service like GitHub.

  • Maintaining different versions of code is called version controlling.
  • Version control stores complete change history like creation, deletion, addition as well as modifications.
  • Git facilitates concurrent contributions using branches.
  • It enables Traceability i.e. tracing bugs using bug tracking software such as Jira.
  • GitHub allows us to host repositories online. So the difference between Git and GitHub is that Git is a version control system that lets you manage and keep track of your source code history whereas GitHub is a cloud-based hosting service that lets you manage Git repositories.
  • Repository: Entire collection of files and folders associated with a project.
  • Commit: Each snapshot of the code is called a commit.
  • Having a full local history makes Git fast.
Git workflow

Git Workflow:

To understand the Git commands better, let’s first understand the Git workflow.

  1. Working Directory
  2. Staging Area
  3. Local Repository
  4. Remote Repository
Git workflow for beginners

Git has three main states (in the working directory) that your files can reside in :

  1. modified means that you have changed the file but have not committed it to your local repository yet.
  2. staged means that you have marked a modified file in its current version to go into your next commit snapshot.
  3. committed means that the data is safely stored in your local repository.
Git commands

Let’s see some of the most used Git commands :

  • git init command creates a new Git repository in the current directory.
  • git checkout -b <branch-name> is used to check out a new branch.
  • git status command displays the state of the working directory and the staging area.
  • git add . command adds all the newly created and modified files in the working directory to the staging area.
  • git add * command adds all the newly created, modified, and deleted files in the working directory to the staging area.
  • git add -u command adds only the modified files in the working directory to the staging area.
  • git commit -a -m "Message here" is a command used to add all files that are staged to the local repository with a message. -a flag is used when there is more than one file to commit.
  • git push origin <branch-name> is a command used to add all committed files in the local repository to the remote repository.
  • git log is a command used to display all the commits.
  • git fetch is a command used to get files from the remote repository to the local repository but not into the working directory.
  • git merge is a command used to get the files from the local repository into the working directory.
  • git pull is a command used to get files from the remote repository directly into the working directory. It is equivalent to a git fetch and a git merge .
  • git rm <file-name> is a command used to remove files from the working directory and the staging area.
  • gitignore is a file that contains names of such files which we don’t want to push to the remote repository.

Steps to add files to Git :

  1. pwd to see the present working directory.
  2. git status : to check the changed files. (Shown in red)
  3. Add the file to the staging area git add .
  4. git status : to check the staged files. (Shown in green)
  5. Commit the files in the staging area so that they can be added to the local repository git commit -am "New files"
  6. Push the file to the remote repository git push origin <branch-name>

I hope you learned something! Thank you for reading.

Click the 👏 to show your support and share it with other fellow Medium users.

You can find me on Twitter and Instagram

Geek Culture

Proud to geek out. Follow to join our +500K monthly readers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store