🚀
🌿 Git & GitHub
1. Git Basics
DevOps

Git Basics

- Version control is a system that records changes to a file or set of files over time so that you can recall specifi...

Mar 202510 min read

Git Basics

  • Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later.
  • A Repository contains all of your project's files and each file's revision history.

3 States

Modified / Un-tracked
  • changes are made in a file but have not been committed.
Staged
  • a modified file is marked and is ready to get committed
Committed
  • a snapshot of the data is permanently stored in git directory.

Creating new Git Repository

  • git init initialises an empty git repository in the current directory. A “.git” file is created and hidden. 700

  • ls -a shows all the files including the hidden files. 700

  • touch hello.txt will create a file named “hello.txt”. 700

Git Status

  • git status shows the status of the git repository. 700

Git Add

  • git add <file> stages the changes of the file. 700

Git Commit

  • git commit -m "<commit_message>" commits to all the staged changes. “-m” adds name to the commit. 700

Git Log

  • git log will show all the history of all commits. 700

Git Restore

  • vim names.txt allows editing the file in the console, when files are modified after they are needed to be staged again. 700
  • git restore --staged <staged_file> will remove staged changes for file from staged (only works after first commit). 700

Git Reset

  • git reset <commit_id> will revert to the commit. 700

Git Stash

  • git stash will neither commit the changes nor will delete all the changes, it just stores the changes somewhere else. 700
  • git stash pop will bring back all the changes stored somewhere else and will be staged. 700
  • git stash clear will remove all the changes that haven’t been staged or committed will be removed. 700

Adding Origin

  • git remote add origin https://github.com/<username>/<repository_link> will link the working directory to the GitHub repository. 600

Git Push

GitHub Personal Access Token (opens in a new tab):

700

  • Click on Generate new token

  • Choose the permissions and validity of the token

  • Copy the token (Store it somewhere safe)

  • git push https://<token>@github.com/<username>/<repository_link> will push all the commits to the repository. 700 700

SSH Keys:
  1. Use git clone git@github.com:<user>/<repository>.git to clone repository. 600
  2. Use ssh-keygen -o to generate SSH key using git. 600
  3. Use cat ~/.ssh/id_rsa.pub (this file contains the private SSH key) and select the contents and copy using Ctrl + Shift + C. 600
  4. Open https://github.com/settings/keys (adding the private SSH key to GitHub), click on new SSH keys. 600 Paste the copied key in key section and add a title. 600
  5. Click on Add SSH key.

Pulling Changes

  • git pull origin will pull all the commits made in the remote repository to the local git directory.

Cloning Repository

  • git clone <repository_link> will download all the files in the remote repository to a local git directory.

How to make contributions to the existing GitHub repository?

Forking a Repository

  • No one except the owner of the GitHub repository is allowed to make changes directly to the repository.
  • Fork allows us to make a copy of the existing GitHub repository with our own ownership and in this repository, we are allowed to make changes directly.
  • The original repository which has been forked is known as the Upstream URL.

© 2026 Driptanil Datta. All rights reserved.

Software Developer & Engineer

Disclaimer:The content provided on this blog is for educational and informational purposes only. While I strive for accuracy, all information is provided "as is" without any warranties of completeness, reliability, or accuracy. Any action you take upon the information found on this website is strictly at your own risk.

Copyright & IP:Certain technical content, interview questions, and datasets are curated from external educational sources to provide a centralized learning resource. Respect for original authorship is maintained; no copyright infringement is intended. All trademarks, logos, and brand names are the property of their respective owners.

System Operational

Built with Love ❤️ | Last updated: Mar 16 2026