Getting familiar with Git

Prashant
3 min readDec 4, 2023

--

While working on a project we all have encounter Git and GitHub. Ever wonder what is it ?

What is Git and GitHub?

  • Git is a Version Control system whereas GitHub is a platform and cloud-based service to store and manage code

What is Version Control system?

  • Think of it as a super smart helper who keeps track of all the changes you make in your magic notebook. So, if you don’t like the new idea, your helper can easily take you back to the original story. It’s like having a time-traveling notebook!

Git and GitHub distributed file system or centralized ?

  • It is distributed since every coder can have its own copy of code which s/he can CRUD.

Some Basic commands

git init

create an empty Git repository or reinitialize an existing one

git add

Moves changes from the working directory to the staging area

git status

displays the state of the working directory and the staging area.

git commit

records changes

git branch

create isolated development environments within a single repository

#new branch
git branch <branch_name>

#delete branch
git branch -d <branch_name>

#force delete
git branch -D <branch_name>

#rename branch
git branch -m <new_branch_name>

other branch commands

git checkout

In addition to checking out old commits and old file revisions, git checkout is also the means to navigate existing branches.

git clean

Remove untracked files from the working directory. This is the logical counterpart to git reset, which (typically) only operates on tracked files.

git log

git log --oneline

display committed snapshot

git commit --amend

Passing the — amend flag to git commit lets you amend the most recent commit

git config

#configuration for user
git config --global user.email "email"
git config --global user.name "username"

to set git configuration

-q 

#or

–Quite

only prints “critical level” messages, Errors, and warnings. All other output is silenced

git fetch

Fetching downloads a branch from another repository, along with all of its associated commits and files. But, it doesn’t try to integrate anything into your local repository.

git merge

A powerful way to integrate changes from divergent branches.

git pull

Pulling is the automated version of git fetch. It downloads a branch from a remote repository, then immediately merges it into the current branch. This is the Git equivalent of svn update

git push

lets you move a local branch to another repository

git reflog

Git keeps track of updates to the tip of branches using a mechanism called reflog. This allows you to go back to changesets even though they are not referenced by any branch or tag.

git reset

Undoes changes to files in the working directory. Resetting lets you clean up or completely remove changes that have not been pushed to a public repository.

git revert

Undoes a committed snapshot. When you discover a faulty commit, reverting is a safe and easy way to completely remove it from the code base.

Extras

* HEAD refers to the currently checked-out branch latest commit.

* Detached HEAD state occurs when the HEAD does not point to a branch, but instead points to a specific commit or the remote repository.

If you’re looking for more or need to dive deep, consider checking out A Guide to Pull, Fetch, Merge and more.

Disclaimer

I am currently in the process of learning and exploring new concepts, including the topics discussed in this content. While I strive to provide accurate and helpful information, please be aware that I might not be an expert in these subjects. Any explanations or guidance offered are based on my current understanding and learning journey.

--

--