# Git Commit, Git Show, and Git Checkout

### **What is Git?**

Before we start, let’s quickly understand what Git is. Git is like a time machine for your code. It helps you save different versions of your work, so you can go back to an older version if something goes wrong. It’s also great for collaborating with others on the same project.

%[https://hashnode.com/post/cm6m3zgd6000209jqhoj04gdc] 

Now, let’s talk about the three commands:

---

## **1\. Git Commit: Saving Your Work**

Think of **Git Commit** as taking a snapshot of your work. When you’re working on a project, you make changes to your files. Once you’re happy with those changes, you can save them using `git commit`.

#### **Step-by-Step: How to Commit**

1. **Make Changes**: Edit your files (e.g., add new code, fix a bug, or write some text).
    
2. **Stage Your Changes**: Before committing, you need to tell Git which changes you want to save. Use the command:
    
    Copy
    
    ```bash
    git add <file-name>
    ```
    
    For example, if you changed a file called `script.js`, you’d type:
    
    Copy
    
    ```bash
    git add script.js
    ```
    
    If you want to stage all your changes, you can use:
    
    Copy
    
    ```bash
    git add .
    ```
    
3. **Commit Your Changes**: Now, save your changes with a message describing what you did. Use:
    
    Copy
    
    ```bash
    git commit -m "Your message here"
    ```
    
    For example:
    
    Copy
    
    ```bash
    git commit -m "Fixed the login button issue"
    ```
    
    This saves your changes in Git’s history.
    

**Why is this useful?**  
Commits let you save your progress step by step. If something breaks later, you can always go back to a previous commit.

---

## **2\. Git Show: Viewing a Commit**

Once you’ve made a commit, you might want to see what changes were made in that commit. That’s where **Git Show** comes in. It’s like opening a photo album to look at a specific snapshot.

#### **Step-by-Step: How to Use Git Show**

1. **Find the Commit ID**: Every commit has a unique ID (a long string of numbers and letters). You can find it by running:
    
    Copy
    
    ```bash
    git log
    ```
    
    This shows a list of all your commits. Look for the commit you want to inspect and copy its ID (you only need the first few characters).
    
2. **View the Commit**: Use the `git show` command followed by the commit ID:
    
    Copy
    
    ```bash
    git show <commit-id>
    ```
    
    For example:
    
    Copy
    
    ```bash
    git show 1a2b3c4
    ```
    
    This will show you the changes made in that commit, including which lines were added or removed.
    

**Why is this useful?**  
It helps you understand what was changed in a specific commit, which is great for debugging or reviewing your work.

---

## **3\. Git Checkout: Switching Between Versions**

**Git Checkout** is like a time-traveling tool. It lets you switch between different versions of your project. You can go back to an old commit or switch to a different branch (a separate version of your project).

#### **Step-by-Step: How to Use Git Checkout**

1. **Find the Commit or Branch**: Use `git log` to see a list of commits or `git branch` to see a list of branches.
    
2. **Switch to a Commit**: If you want to go back to a specific commit, use:
    
    Copy
    
    ```bash
    git checkout <commit-id>
    ```
    
    For example:
    
    Copy
    
    ```bash
    git checkout 1a2b3c4
    ```
    
    This will take you back to the state of your project at that commit. (Note: This puts you in a “detached HEAD” state, which means you’re not on a branch. To go back, you can switch to a branch using `git checkout main` or `git checkout master`.)
    
3. **Switch to a Branch**: If you want to switch to a different branch, use:
    
    Copy
    
    ```bash
    git checkout <branch-name>
    ```
    
    For example:
    
    Copy
    
    ```bash
    git checkout feature-login
    ```
    
    This switches your project to the `feature-login` branch.
    

**Why is this useful?**  
It lets you explore different versions of your project without losing your current work. You can always switch back to where you were.

---

### **Quick Recap**

* **Git Commit**: Save your changes with a message.
    
* **Git Show**: View the details of a specific commit.
    
* **Git Checkout**: Switch between different versions or branches.
    

---

## linkedin: [**https://www.linkedin.com/in/khushi-dubey-6036a2305**](https://www.linkedin.com/in/khushi-dubey-6036a2305)

# Thank You!
