# Advanced Git : 10 Git Commands Senior Devs Actually Use

Here are ten Git commands for inspecting changes, working with branches, and managing commits. I’ll explain what each does and when I use it.

Author: Vladislav Guzey
Published: 2025-09-08
Canonical: https://proflead.dev/posts/git-for-advance-users/


<div class="videoWrapper">
  <iframe width="100%" src="https://www.youtube.com/embed/3gz4DxYix7Y?si=jYbNreSeKMwEPrcT" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
</div>

Here are ten Git commands for inspecting changes, working with branches, and managing commits. I’ll explain what each does and when I use it.


## Stage and Commit in One Command

Instead of using two separate commands to stage your modified files and then commit them, you can do it all in one go.

Normally, you would use **_git add ._** followed by **_git commit -m “message”._** But you can combine these into a single, efficient command:

```bash
git commit -am "message"
```
This command stages modified and deleted tracked files, then commits them with your message. Add new files with `git add` first.

## Create and Switch to a New Branch

Here’s another great shortcut. To create a new branch and immediately switch to it, you can combine two commands into one. Instead of **_git branch <new-branch>_** and then **_git checkout <new-branch>_**, you can use:
```bash
git checkout -b <new-branch>
```
This single command creates the new branch and switches your working directory to it.

## Rewrite the Most Recent Commit

If you need to change the most recent commit, you can use the **_amend_** command. This is useful for changing the commit message or adding more changes to the last commit. You can also use a shortcut to directly change the commit message in one line:
```bash
git commit --amend  
git commit --amend -m "new message"
```
## View a File from Another Branch

To view a file from another branch without switching branches, use:
```bash
git show <branch-name>:<file-name>
```
For example, to see the README.md file from the main branch, you would use:
```bash
git show main:README.md
```
## Sort Branches by Commit Date

To sort branches by their most recent commit date, use:
```bash
git branch --sort=-committerdate
```
You can even set this as your global default with:
```bash
git config --global branch.sort -committerdate
```
## Undo a Commit While Keeping Changes

If you want to undo the last commit but keep all the changes in your working directory, this is the command for you.
```bash
git reset --soft HEAD~1
```
The `git reset --soft HEAD~1` command moves HEAD back one commit and keeps the changes staged, ready to be committed again.

## **Reset commit history and optionally discard or keep changes**

Moves the `HEAD` pointer back one commit and unstages the changes, leaving them in your working directory.
```bash
git reset --mixed HEAD~1
```
Moves `HEAD` back and discards both the staged and working directory changes.
```bash
git reset --hard HEAD~1
```
These commands combine history manipulation with controlling what happens to your local modifications.

## Enhanced Logs

The default git log can be a bit plain. You can get a more detailed and visually appealing log with these commands:

This shows the commit message, which files were changed, and how many lines were added or removed.
```bash
git log --decorate --stat
```
This provides a compact, graphical view of your commit history, making it easier to see branches and merges.
```bash
git log --graph --oneline --decorate
```
## Video Tutorial: Git Commands with Examples

**_Watch on YouTube:_** [**_Git Commands for Pro_**](https://youtu.be/3gz4DxYix7Y)

## Conclusion

I hope you found these advanced Git commands helpful. If you liked this tutorial, please give it a thumbs up and share it with other developers.

If you want to share other useful commands, please do it in the comments below!

Cheers! ;)

