Git in practice: for absolute beginners

Komal Swami
4 min readMar 8, 2024

Overview

Architecture

Basic commands walkthroug

Imagine working on a project with your friends, now you want to work on a certain module and your friend on another. how would you collaborate?

It was working before adding this new functionality and now everything seems to fall apart. what will do in this situation?

Here git comes into the picture. git is the version control system. you can keep track of your code and revert to specific points in an emergency.

this article is a basic guide for absolute beginners. in case you already know git, it might be a good walkthrough for you too.

Architecture :

git architecture in a nutshell :

  • The Working Directory is where you do your work.
  • The Staging Area is where you prepare your changes.
  • Local Repository is where Git stores the complete history.
  • Commits are snapshots of your project.
  • Branches allow you to work on different parts simultaneously.
  • HEAD points to the latest commit in your active branch.

Basic commands to get started with

git init :

The first thing you need to do is start using git in your project by initializing git in it. How? open the command prompt and run.

git init

hey git, keep track of these files. git always hangs on the very top of the folder structure and keeps track of all files’ hierarchy, taking care of hierarchy.

git add :

Now, you can add files to be tracked by git.

git add .

you can use . for adding all files or specify the names of the files.

git commit :

git commit -m “expressive message which will say what you have done in this commit!”

git log :

The Git log will give you history of your commits. How many commits have been made, who made those, and what time they were made? git log will give you logs about it.

git log -n 2

git log — author=”komal”

— since=2018–07–14

— until=2018–07–14

one more thing you will notice here is the HEAD. the head is the pointer that always points to the tip of your current branch/commit.

git clean :

git clean is a Git command used to remove untracked files from your working directory. Untracked files are files that Git is not currently managing, and they are not included in the repository. This command helps clean up your working directory by removing files that are not needed.

git clean -m

git clean -f

git clean -n → what is about to clean

cleans your local area. not your staging area.

git diff :

The git diff command in Git is used to show the differences.It can be used to compare changes between different commits, branches, or the working directory.

Compare local change with last commit

git diff

Compare local change with stagged changes

git diff — stagged

Compare different commits

git diff commit1 commit2

Compare different branches

git diff branch1 branch2

delete files :

The git rm is used to remove a file from both your working directory and the Git repository.

git rm filename.txt

gitignore :

sometimes you don’t want to upload temp files or log files so you can mention them in your git ignore file and git will not track them.

Imagine having added and committed a file that you want to ignore later on. you will list that file in git ignore file but it will be not ignored because git is already tracing that file so you have to

git rm — cached filename

It will not be deleted but git will stop tracking it

git stash :

The git stash is used to temporarily save changes that are not ready to be committed, allowing you to switch to a different branch or work on something else. This is particularly useful when you have changes in your working directory that you want to set aside without committing them.

git stash

you can get back those changes by poping the stash

git stash pop

I hope you loved it as much as I did writing it. I have covered more advanced commands in this article please check that out to know more. Thanks for reading till the end! Happy coding!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Komal Swami
Komal Swami

Written by Komal Swami

Full Stack Developer || ML/DL enthusiastic

No responses yet

Write a response