JavaScript Development Space

Essential Git Command Reference: The Core Operations Every Developer Needs

2 May 20254 min read
15 Git Commands That Cover 90% of a Developer’s Daily Workflow

If you're new to Git or only use it occasionally, you’ve likely googled “most useful Git commands” more than once. This guide is for you. It won’t cover everything Git can do, but it focuses on the most practical commands that will save you time and headaches during day-to-day development.

Let’s dive in.

1. git init

Creates a new Git repository in the current folder.

git init

This sets up Git tracking for your project. It creates a .git directory containing metadata about your repo, including commit history, branches, and remote settings.

2. git clone

Creates a local copy of a remote repository.

git clone #repository-url

Example:

git clone https://github.com/test/hello-world.git

This copies all the files, history, and branches from the remote repo.

3. git status

Shows the current state of your working directory and staging area.

git status

You’ll see:

  • Files that have been modified
  • Files that are staged
  • Untracked files

This is one of the most frequently used Git commands.

4. git add

Adds files to the staging area so they’re ready to be committed.

git add #file
git add .
  • git add #file adds a specific file.
  • git add . adds all changes in the current directory and subdirectories.

Tip: Use git status before running this to see which files you’re staging.

5. git commit

Saves a snapshot of your staged changes with a message.

git commit -m "@feature auth added"

Each commit should describe why the changes were made—not just what was changed.

Use clear, concise messages that help teammates (and your future self) understand the history.

6. git diff

Shows differences between your working directory and the staging area or between commits.

git diff # changes not yet staged
git diff --staged # staged but not yet committed

This helps you preview what’s going to be committed or what changed between commits.

7. git log

Displays the commit history.

git log

You’ll see:

  • Commit hashes
  • Author names
  • Dates
  • Commit messages

To simplify the view:

git log --oneline --graph --decorate

This gives a compact visual history with branches and tags.

8. git reset

Resets your staging area or moves HEAD to a different commit.

Undo staged changes:

git reset #file

Undo a commit (but keep your changes):

git reset --soft HEAD~1

Undo a commit and remove changes:

git reset --hard HEAD~1

⚠️ Be careful with --hard — it deletes your changes.

9. git checkout

Switches branches or restores files.

Switch to a branch:

git checkout main

Restore a file to the last committed version:

git checkout -- index.html

Since Git 2.23, the safer alternative is to use:

git restore #file
git switch #branch

10. git branch

Lists, creates, or deletes branches.

List branches:

git branch

Create a new branch:

git branch @feature/login-form

Delete a branch:

git branch -d old-feature

11. git merge

Combines changes from one branch into another.

git checkout main
git merge @feature/login-form

This merges the feature branch into the main branch.

If there are conflicting changes in the same files, Git will prompt you to resolve them manually.

12. git pull

Downloads changes from a remote repository and merges them into your local branch.

git pull origin main

This is equivalent to:

git fetch
git merge

Use git pull --rebase to avoid unnecessary merge commits.

13. git push

Uploads your local commits to a remote repository.

git push origin main

Use this to share your work with others.

14. git stash

Temporarily saves changes that you don’t want to commit yet.

git stash

This clears your working directory so you can switch branches cleanly.

Restore stashed changes:

git stash pop

View all stashes:

git stash list

15. git remote

Manages remote repositories.

List remotes:

git remote -v

Add a new remote:

git remote add origin https://github.com/user/repo.git

Rename a remote:

git remote rename origin upstream

Final Tips

  • Use git status and git log often — they’re your safety net.
  • Don’t be afraid of branching and stashing — they help you experiment safely.
  • Always write meaningful commit messages.

Learning these 15 commands gives you a strong foundation for working with Git in most real-world scenarios.

JavaScript Development Space

JSDev Space – Your go-to hub for JavaScript development. Explore expert guides, best practices, and the latest trends in web development, React, Node.js, and more. Stay ahead with cutting-edge tutorials, tools, and insights for modern JS developers. 🚀

Join our growing community of developers! Follow us on social media for updates, coding tips, and exclusive content. Stay connected and level up your JavaScript skills with us! 🔥

© 2025 JavaScript Development Space - Master JS and NodeJS. All rights reserved.