30+ Git Commands That I Frequently Use

Full-Stack Developer, Entrepreneur and Co-Founder of Coderplex.
Building https://coderplex.in
Checkout my portfolio at https://bhanuteja.dev
Search for a command to run...

Full-Stack Developer, Entrepreneur and Co-Founder of Coderplex.
Building https://coderplex.in
Checkout my portfolio at https://bhanuteja.dev
Thank you for the article. I have an addition:
git checkout . was "replaced" by git restore .. You can also use git restore --staged . to unstage files.
You also repeated git push --delete origin new-feature both in the comment and the codeline. I think you want -d for the shorter version. (;
Hey, thanks for pointing these out. Will make these corrections.
Authored in connection with the Write With Fauna program. Table of Contents Authentication Setting up Fauna in Next.js Installing Fauna Setting up Migrations Tool Authentication and Authorization in Fauna Next.js Serverless Function Setup for Fa...

I wanted to start blogging in Aug of 2020. I decided to use @hashnode for my blog. It was the best decision that I made. I wrote 27 technical articles so far. Most of them are about frontend web development. A thread 🧵 about each of these articles i...

Next.js has become my go-to framework for almost every project that I make. So, I made a starter template that I can just use and get started easily. In this article, I will show you how to use the starter template that I made and deploy it with Verc...

In this article, we will see the order in which different useEffect callbacks and cleanups happen. We will also see how it differs when the app mounts, unmounts, updates. This image is taken from https://github.com/donavon/hook-flow. I took the ex...

Bhanu Teja Pachipulusu's blog
29 posts
Developer, Indie Maker and Blogger. Currently building MDX.one
Checkout my portfolio
In this article, I will list out all the git commands that I use very frequently. This is not in any way a complete list, just the commands that I use very often. This is intended to be used as a quick reference to perform an action that you want.
# Create 'blogs' folder and clone the 'pbteja1998/blogs' repo into it
git clone https://github.com/pbteja1998/blogs.git
# Create `my-blogs` folder and clone the `pbteja1998/blogs` repo into it
git clone https://github.com/pbteja1998/blogs.git my-blogs
# Initializes the current directory as a git repo
git init
# Adds the file contents to the index
# Ready to be committed next time you run `git commit`
# By default, Ignores the files present in `.gitignore`
# Add a single file
git add README.md
# Add all the files in the current directory
git add .
# Also adds the files present in `.gitignore`
git add -f .
# Commits/Records the changes to the local repo
git commit -m "some message"
# Does not create a new commit
# Adds the changes to the most recent commit
git commit --amend
# Shows the status of the working tree
git status
# Shows the output in short format
git status -s
# Shows the branch even in short format
git status -sb

# Shows the commit logs
git log

# Shows the changes between unstaged files and the commits
git diff
# Shows the changes between staged(ready-to-be-committed) files and the commits
git diff --staged

# Shows all the remotes configured and their remote URL
git remote -v
# Adds a remote
# git remote add <remote-name> <remote-url>
git remote add upstream https://github.com/something/blogs.git
# Changes the URL of the remote
git remote set-url upstream https://github.com/some-thing/blogs.git

# Switch to branch
# git checkout <branch>
git checkout master
# Creates a new branch and switch to that
git checkout -b new-feature
# Removes all the unstaged changes in the current directory
git checkout .
# Removes all the unstaged changes for a file
git checkout -- README.md
# Pushes the local changes to the remote to keep it up-to-date
git push origin master
# Force push the local changes to the remote
# Usually git will not allow you to push to the remote if the remote has some commits that are not present in the local repo
# This will override that check and lets you force push to the remote
# This may cause the remote to lose some commits. So use it carefully.
git push -f origin master
# Push and set the remote as upstream
# same as `git push --set-upstream origin feature-branch`
git push -u origin feature-branch
# Deletes the branch in the remote
# same as `git push --delete origin new-feature`
git push -d origin new-feature
# Deletes the branch locally
# same as `git branch --delete feature-branch`
git branch -d feature-branch
# Force delete a branch even if it's not merged
# same as `git branch --delete --force feature-branch`
git branch -D feature-branch
# Removes all the files and directories that are not yet tracked by git
git clean -fd
# Merges the <branch> to the current branch
# git merge <branch>
git merge feature-branch
# Fetches the changes from the remote and merge it into local repo
git pull origin master
# Removes all the changes to the tracked files that have not yet been committed
git reset --hard
The next article will most probably be a part of My Review of Kent C. Dodds's EpicReact.Dev. Check out the series page for more info.
If you liked this article, check out
If you have any comments, please leave them below or you can also @ me on Twitter (@pbteja1998), or feel free to follow me.