6 Common Git Mistakes and How to Fix Them

6 Common Git Mistakes and How to Fix Them

Git can be your best friend as a developer, but it can also be the source of quite a lot of errors in your workflow. Here’s a list of the most common ones, the day-to-day problems, and how to fix them.

Git can be your best friend as a developer, but it can also be the source of quite a lot of errors in your workflow. Here’s a list of the most common ones, the day-to-day problems, and how to fix them.

Note: if any command shown is unknown to you, you can find official Git docs links to them at the bottom of the article.

1. You Misspelt the Last Commit Message

You realize you just pushed a commit where you misspelt something like "Fix lanting page" and you don’t want to sound dumb with your colleagues.

Simply use:

git commit --amend 

Or

git commit --amend -m "Fix landing page"

This command will let you combine any staged changes with your last commit. If nothing is staged, you can use it to update the commit message like in this case, either via a new CLI prompt, as the first command will show, or directly, as the second command will do.

2. You Forgot a File in Your Last Commit

You can use git commit --amend on this occasion too, supposing, for example, you forgot a file in your last commit.

Just add it to the staging area and then run the command again.

git add landingpage.js
git commit --amend

3. You Pushed a Commit That Has a Problem in It

You realized you pushed a commit with some code you thought was good to go, but it was actually not that acceptable.

You can fix this by running:

git revert <SHA>

This command is going to create an opposite commit of the one you got wrong. Kind of like throwing water on a fire. Anything removed in the old commit will be added in the new reverted one, and similarly, previously added content will be cut.

javascript web-development programming github git

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Why Web Development is Important for your Business

With the rapid development in technology, the old ways to do business have changed completely. A lot more advanced and developed ways are ...

Important Reasons to Hire a Professional Web Development Company

    You name the business and I will tell you how web development can help you promote your business. If it is a startup or you seeking some...

Things About Git and Github You Need to Know as Developer

Hey there, in this blog we are going to learn about Git and Github. As a developer, you might have come across the terms Git and Github but do you understand why do you need or why you are using these? Let’s dig a little deeper to understand these terms.

What Garbage Collection in JavaScript Is and How It Works

JavaScript values are allocated when things are created (objects, Strings, etc.) and freed automatically when they are no longer used. This process is called Garbage collection.

What Javascript Spread Operator is, How It Works and How to Use It

JavaScript spread operator is one of the more popular features that were introduced in ES6. This tutorial will help you understand it. You will learn what spread operator is and how it works. You will also learn how to use it to copy and merge arrays and object literals, insert data and more.