Web errors and solutions

10 Essential Git Commands to Save Time

BlogApril 3, 202517 min
10 Essential Git Commands to Save Time
Contents

💡 Why mastering Git commands is essential for saving time

In the daily life of a web developer, mastering Git commands is much more than a simple bonus: it's a genuine lever for efficiency. Git, the most popular distributed version control system in the world, makes it easy to manage the versions of your code, collaborate with others and secure every step of your development. Yet many developers don't take full advantage of the most powerful Git commands.

Whether you're a freelance developer, an employee at a tech company, or even a computer science student, knowing how to use the essential Git commands can save you precious time, prevent critical mistakes and improve the quality of your projects.

In this article, I invite you to discover the 10 most useful Git commands — the ones I personally use every day to work faster, with less stress and better organisation. You'll find both indispensable basics and tips to take your Git mastery further.

🔗 For beginners, I also recommend the official Git documentation, a comprehensive resource for diving deeper into each command.

🧰 Git commands #1: git status – The indispensable starting point

The first of the Git commands you absolutely need to know is git status. It's a simple but essential command for staying in control of what you're doing in your repository.

When you run git status, Git tells you precisely:

• ✅ which files have been modified since the last commit,

• 🕒 which ones are ready to be saved (staged),

• 🧩 and which ones aren't tracked by Git (untracked files).

📌 Example of use:

git status

Typical output:

On branch main
Your branch is up to date with 'origin/main'.

Changes not staged for commit:
  modified:   style.css
  modified:   script.js

Untracked files:
  new-script.js

🎯 Why this Git command is indispensable

Before running other Git commands like git add or git commit, it's crucial to run a git status. This keeps you from forgetting important files or mistakenly including unwanted ones. It's like doing a check-up before taking action.

💡 Pro tip: Create a short alias for this command in your terminal:

git config --global alias.s status

You'll then be able to simply type git s!

📚 To go further:

👉 Check the official git status help page to see all the available options.

💾 Git commands #2: git add . – Add all modified files at once

Among the most used Git commands, git add . is one of the fastest to run. It lets you add all the modified files in the current directory (and its subfolders) to the staging area.

In other words, with a single line, you're telling Git: "I want all these files to be included in the next commit."

⚙️ Example:

git add .

This command is handy when you know exactly what you're changing. It saves you from having to list each file manually.

⚠️ Warning: git add . also adds untracked files. It's therefore strongly recommended to run a git status beforehand, to avoid adding sensitive or useless files (such as .env, .DS_Store, or test files that aren't ignored).

🎯 A more granular alternative

If you prefer to manually select each modified file, you can use:

git add fichier.css

Or, even better:

git add -p

This interactive variant (-p for patch) lets you choose, line by line, what you want to add. A powerful feature when you want cleaner, more segmented commits.

📚 Recommended reading:

👉 For more details, see the official Git documentation on add.

🧱 Git commands #3: git commit -m "message" – Document your work effectively

In the list of indispensable Git commands, git commit is undoubtedly one of the most fundamental. It lets you save a snapshot of your changes in the project's history. In other words, this is the moment your work becomes traceable.

The -m option lets you add a short message describing the changes. This is what's known as a commit message.

✍️ Basic example:

git commit -m "Ajout de la fonction de recherche"

🎯 Why a good commit message matters

Commit messages are crucial for understanding a project's history, especially in a team. A good commit message should meet these three criteria:

1. ✅ Clear: the message should be understandable even weeks later.

2. 🧠 Precise: state what was changed (addition, fix, removal, etc.).

3. ⏳ Concise: keep it brief but informative.

💡 Tip: Follow the Conventional Commits format to standardise your messages.

Example:

git commit -m "feat: ajout de la fonctionnalité de contact"

🔄 Example of a bad message:

git commit -m "fix"

❌ Too vague. Nobody will know what was fixed.

Good use of this Git command makes code reviews, git log, and any git revert easier.

📚 Useful external resource:

👉 Git Commit Guidelines by Chris Beams: a classic for learning how to write good commit messages.

🔄 Git commands #4: git pull – Fetch the latest changes from the remote repository

Among the essential Git commands for any collaborative work, git pull holds a place of honour. This command lets you update your local branch with the changes from the remote repository — in other words, retrieve the work of other team members, or your own if you work across several machines.

It's often the first command to run at the start of a work session, in order to avoid any conflicts later on.

⚙️ How it works at its core

git pull

This command actually combines two operations:

1. git fetch: it retrieves the latest changes from the remote repository.

2. git merge: it merges those changes into your current branch.

The result: you're perfectly up to date.

🧠 Best practices

Always run a git pull before you start coding to avoid unnecessary conflicts.

• If you work in a team, forgetting this command can cause bugs or unexpected loss of code during a push.

⚠️ In case of a conflict

If your changes conflict with those in the remote repository, Git will display a conflict message. You'll then need to resolve the conflicts manually, often by opening the files and choosing which version to keep.

💡 Tip: If you want to review the changes before merging them, use git fetch followed by git merge instead.

📚 Useful resources to dig deeper into this Git command:

👉 Full explanation of git pull on Atlassian

🚀 Git commands #5: git push – Send your changes to the remote repository

Among the indispensable Git commands, git push is the one that lets you share your work with other developers. Once your changes have been validated with git commit, it's git push that sends them to the remote repository (GitHub, GitLab, Bitbucket, etc.).

Without this command, your changes stay only on your machine — invisible to your collaborators or your continuous integration tools (CI/CD).

⚙️ Basic command:

git push

This shortcut works if you've already set up a tracking branch.

But the more explicit version is often preferable:

git push origin main

or:

git push origin nom-de-la-branche

This clearly tells Git which local branch you want to push to which remote repository (origin being the default name of the repository).

🔐 Security tip & best practice

It's recommended to review your changes via git status and git log before a push. Indeed, once the code is pushed to the remote repository, it becomes accessible to everyone and can trigger automations (build, tests, deployments, etc.).

💡 Advice: To avoid accidental pushes, configure your repositories with branch protection (via GitHub, for example) to enforce code reviews or automated tests.

📚 Learn more:

👉 GitHub documentation on git push

🧪 Git commands #6: git checkout -b – Create a new branch cleanly

Working efficiently with Git also means knowing how to organise your code. And for that, branch management is paramount. Among the Git commands related to branches, git checkout -b is one of the most practical. It lets you create a new branch and switch to it immediately, all in a single line.

It's an ideal command for kicking off a new feature, fixing a bug or testing an idea without disrupting the main branch (main or master).

⚙️ Basic example:

git checkout -b feature/contact-form

With this Git command, you create a branch named feature/contact-form based on your current branch, and you switch to it automatically. It's the equivalent of two merged commands:

git branch feature/contact-form
git checkout feature/contact-form

🤝 Why this Git command is essential in a team

When several developers collaborate on the same project, working on independent branches makes it possible to:

• avoid disrupting the production code,

• make code review easier (via pull requests),

• and test each feature in isolation.

💡 Tip: adopt a naming convention such as feature/, bugfix/, hotfix/, test/ to keep your branches well organised.

📚 External resource:
👉 Complete guide to Git branches – Atlassian

🔍 Git commands #7: git log – Track the commit history with clarity

Among the Git commands that let you analyse a project, git log is a must. It displays all the commits made, in reverse chronological order (from most recent to oldest). With this command, you can trace the changes, identify the contributors and understand how the code has evolved.

It's the perfect tool for:

• finding a specific change,

• diagnosing a bug,

• or simply following the project's history in detail.

⚙️ Basic command:

git log

This Git command returns detailed information for each commit:

• the commit's unique identifier (SHA),

• the author's name,

• the date and time,

• the commit message.

🔎 Tip: compact and visual view

If you find the default output too verbose, you can opt for a condensed, graphical version:

git log --oneline --graph --all

This mode shows you:

• each commit on a single line,

• the branch structure via ASCII lines,

• and the full history, including merged branches.

Perfect for visualising a project's Git flow.

🧠 Other useful options:

• git log -n 5 → Displays the last 5 commits

• git log --author="Kylian" → Filters commits by author

• git log --since="2 weeks ago" → History limited to a time period

🧠 Other useful options:

• git log -n 5 → Displays the last 5 commits

• git log --author="Kylian" → Filters commits by author

• git log --since="2 weeks ago" → History limited to a time period

♻️ Git commands #8: git reset – Undo cleanly without panicking

Among the advanced Git commands, git reset is undoubtedly one of the most powerful… but also one of the trickiest to handle. It lets you undo changes, revert to an earlier state of the project, or remove files from the staging area.

Used correctly, it will save you from embarrassing mistakes. Used wrong, it can make code disappear for good. That's why this Git command must be used with caution, especially in a collaborative environment.

🧪 The three main types of git reset

1. git reset --soft HEAD~1

Undoes the last commit, but keeps all the files in staging.

Very useful if you want to redo a commit with a better message or group several changes together.

git reset --soft HEAD~1

2. git reset --mixed HEAD~1 (default)

Removes the commit and takes the files out of staging, without deleting the local changes.

It's the safest form for fixing a recent mistake without losing your code.

git reset HEAD~1

3. git reset --hard HEAD~1

⚠️ Danger ahead: this command deletes the last commit AND all the associated local changes. It's irreversible if you don't have a backup.

git reset --hard HEAD~1

🎯 When should you use this Git command?

• You committed too early or committed too much.

• You want to undo a commit without leaving a trace.

• You want to "reset" a project to a stable version.

💡 Tip: before a reset --hard, consider creating a backup branch:

git branch backup-temp

📚 External resource:

👉 Full explanation of the git reset options on Git-SCM

🧼 Git commands #9: git clean -fd – Clean up untracked files to start from a clean base

In some cases, your local project can end up cluttered with temporary files, test files, or automatically generated folders that haven't been added to Git. This is where the git clean command becomes valuable.

Among the "cleanup"-oriented Git commands, git clean -fd is the one that lets you delete all untracked files and all unversioned directories.

⚙️ Example of use:

git clean -fd

• -f: forces the deletion (otherwise Git protects you)

• -d: includes untracked folders, not only files

🧠 When should you use this Git command?

• After testing automatically generated code

• Before an important commit, to start from a clean environment

• When a project contains leftovers from old ignored files

⚠️ Warning: This Git command is irreversible. Once the files are deleted, they can't be restored if they're not versioned.

🔒 Security tip:

Before launching a permanent cleanup, you can simulate the result with the -n option (or --dry-run):

git clean -fdn

This will display the list of files that would be deleted, without touching anything.

📚 External resource:

👉 Complete guide to git clean – Atlassian

🧬 Git commands #10: git stash – Set your changes aside without losing them

Among the Git commands that are lifesavers on a daily basis, git stash is a real gem. It lets you set aside your uncommitted local changes without having to commit or delete them. It's the perfect command when you need to interrupt one task to handle another quickly, without risking breaking your work in progress.

🔄 Typical scenario:

You're working on a new feature (feature/search) and a colleague asks you to fix an urgent bug on the main branch.

➡️ Thanks to git stash, you can:

1. Save your changes in progress

2. Switch to the main branch

3. Fix and push

4. Return to your branch and pick your work back up right where you left it

⚙️ Main commands:

git stash

→ Saves your local changes and restores a "clean" copy of the branch

git stash pop

→ Restores the last stash and removes the entry from the list

git stash apply

→ Restores the changes without removing the stash (useful if you want to reuse them)

git stash list

→ Lists all the saved stashes

💡 Useful tip:

You can add a message to your stash to find your way around more easily:

git stash save "Début refonte formulaire de contact"

And to apply a specific stash:

git stash apply stash@{2}

🎯 When should you use this Git command?

• To interrupt your work without losing your changes

• To test something quickly

• To temporarily switch to another branch without committing unfinished code

📚 External resource:

👉 Official Git documentation on stash


🔎 Bonus: Other useful Git commands worth knowing to go further

In addition to the 10 essential Git commands covered above, there are many other very handy commands to build into your developer routine. Here are a few that are worth a look to refine your Git mastery and boost your efficiency.

🧰 A selection of bonus Git commands:

git diff – Compares the differences between two versions of a file or a project. Very useful for seeing what's been changed before a commit:

git diff

git branch – Lists all the existing branches and tells you which one you're currently on:

git branch

git rebase – Lets you reorganise commits, clean up the history or merge branches in a linear way. To be used with caution:

git rebase main

git clone – Used to copy an existing Git repository from a remote platform like GitHub or GitLab:

git clone https://github.com/nom-utilisateur/mon-projet.git

git fetch – Retrieves the changes from the remote repository without merging them into your current branch. Very handy if you simply want to check what's changed:

git fetch

💡 Tip: The more you explore these Git commands, the more capable you become of adapting Git to your own development workflow.

📚 Recommended resource:

👉 Git Cheatsheet – GitHub: a very useful cheat sheet with the main Git commands to keep within reach.

💡 Why these Git commands genuinely save you time

As a web developer, your time is precious. Mastering these Git commands isn't just a matter of comfort: it's a powerful lever to work more efficiently, avoid costly mistakes and collaborate better with your team or your clients.

Here are a few concrete examples of what these Git commands let you avoid day to day:

• ❌ Conflicts during poorly anticipated git pulls

• ❌ Files forgotten in your commits

• ❌ Loss of code caused by a wrong manipulation

• ❌ Hours of work lost starting everything over after a bug

By building these essential Git commands into your workflow, you turn Git into a genuine safety shield and a productivity assistant. You'll feel more comfortable experimenting, fixing, shipping and collaborating without stress.

Whether you're a freelancer, an agency employee or a solo full-stack developer, these good Git practices reinforce your professional rigour and let you ship cleaner code, faster, and with greater peace of mind.

✍️ Conclusion: Adopt these Git commands to step up to the next level

These 10 essential Git commands, together with the bonuses shared above, represent the foundations of a clean, fast and secure Git workflow. Whether you're still in training or already on the job, mastering them will let you work more efficiently, collaborate without fear and avoid many of the mistakes that a lot of developers still make.

By building these Git commands into your daily routine, you'll gain:

• time,

• clarity,

• and peace of mind in every one of your projects.

👉 Looking for a freelance developer to create or optimise your website?

Visit my portfolio here or contact me directly to discuss your project.

Share

Comments

Be the first to react to this article.

Leave a comment

Your email stays private. Comments are published after review.

A web project to launch?

I'll help you scope it, design it and launch it properly.