Git Articles

How to remove a specific commit from the history

You want to remove a specific commit from the history. You can do this with git rebase -i.

How to invert 2 commits in Git

Let's see how to change the order of commits in Git and rewrite commit history

How to rebase your git branch

You worked on a branch and are ready to merge it into main. But main has changed since you started working on your branch. You need to rebase your branch on top of main.

How to revert a git merge

You have merged a branch to your current branch and a few commits later you realize that you want to revert that merge. How do you do it?

How to see the differences between 2 branches in git

You have been working on a feature branch for a while, and you want to see the differences between that branch and the main branch. How do you do that?

How to rewrite a comment of a specific commit

Sometimes you need to rewrite a comment of a specific commit. This is how you do it.

How to restore a deleted file from a Git repository

In a previous commit, you deleted a file that you now need back. How do you restore it?

How to revert a file to a specific commit

You made some changes to a file, but you want to revert that file to a specific commit. This is the only file you want to revert. You don't want to revert the entire repository.

How to restore a branch after someone did a git push --force

You are sharing a branch with another developer and this developer did a git push --force and you want to resume work on that branch without losing your local commits.

How to squash all commits in a branch?

You have been working for a while on a feature branch, but before merging it to main you want to squash all commits into a single one. How do you do that?

How to handle locally modified configuration files

One of the most common problems when working with git is how to handle configuration files that are modified locally. This post shows how to handle this situation.

How to delete a branch

Let's see how we can delete a branch both locally and remotely.

git push --force-with-lease

It is usually not recommended to use git --force on a shared branch. Let's see how git push --force-with-lease can help.

What is the difference between git checkout branch vs git checkout origin/branch?

It is important to understand how Git manages refs in order to understand how some of the Git commands operate.

How to amend the last commit in Git?

The git amend is usually used to change the last commit message, but it can also be used to change the content of the last commit itself.

git restore

Let's review the different use cases of the git restore command

what is the git index?

This article describes how gits manages the index, aka staging area, aka cache.

How to stop tracking a file in Git without deleting it?

You added a file to Git, but now you want to stop tracking it. You don't want to delete it, you just want to stop tracking it. How do you do that?

How to remove a commit that has already been pushed?

You just ran git push, sending your changes to your remote server, now you realize there’s a problem with one of those commits. You’d like to undo that commit.

How to undo a git add?

How to remove a file from the staging area?

How to get just one file from another branch?

You want to retrieve a file from another branch, but you don't want to merge the whole branch into your current branch.

What is the difference between git diff HEAD vs. git diff --staged?

Git diff is a very useful command to show the difference between different states of the repository. In this article, we will explore the different options of the git diff command.

How to remove the most recent local commits?

You accidentally committed the wrong files to Git, but didn't push the commit to the server yet. How to remove those commits from the local repository?

How to move commits from master to another branch?

You made a series of commits on the master branch, which in hindsight you should have been made in another branch. How to move those commits to another branch?