Behind every great developer is a strong command of Git. Whether you're working solo or on a large team, mastering these essential Git commands will make your version control smoother, safer, and smarter. Let's gear up with the tools you need to navigate any project confidently.

1. Staging All Changed Files

To stage all modified files in your project, you can use the following command:

git add *


This command stages all changes in the current directory and it’s subdirectories, including new and modified files.

2. Commit All Staged Files with a Message

Once you have staged your changes, the next step is to commit them. Use the following command to commit all staged files along with a descriptive message:

git commit -m "commitMessage"


This command takes all the files that were previously staged and records them in the Git history along with the message you provide. A clear and meaningful commit message helps you (and your team) understand the changes at a glance.

3. Push Changes to a Branch

After committing your changes locally, you need to push them to the remote repository. Use the following command:

git push


This command uploads your committed changes to the remote branch you are currently working on. It's an essential step for collaboration, ensuring that your teammates have access to your latest updates.

4. Pull Changes from a Branch

To fetch and merge changes from a remote repository into your local branch, use:

git pull


This command updates your local working directory with the latest changes from the remote branch. It’s a combination of git fetch (to retrieve changes) and git merge (to integrate them into your current branch), helping you stay up-to-date with your team’s work.

5. Show the Current Branch

To display the name of the branch you are currently working on, use:

git branch --show-current


This command quickly tells you which branch is active in your local repository. It's especially useful when you're working across multiple branches and want to confirm your current context before making changes.

6. Create a New Branch

To create a new branch without switching to it, use the following command:

git branch "branchName"


This command creates a new branch with the specified name, allowing you to start working on features, fixes, or experiments without affecting the main codebase. Remember, after creating the branch, you'll need to switch to it manually if you want to start working there.

7. Switch to Another Branch

To switch between branches in your local repository, use:

git checkout "branchName"


This command moves you to the specified branch, allowing you to work on different features or fixes without affecting the current branch. It's essential when you're collaborating or managing multiple tasks in different branches.

8. Stash Changes

When you need to quickly switch tasks without committing incomplete work, you can temporarily save your changes using:

git stash


This command saves your uncommitted changes and reverts your working directory to the last commit. It's perfect for when you need to switch branches or work on something else without losing your progress. You can later reapply the stashed changes when you're ready.

9. Apply Stashed Changes

To reapply the changes you previously stashed, use:

git stash apply


This command applies the most recent stash to your current branch without removing it from the stash list. It's useful when you want to pick up where you left off after temporarily shelving your work.

10. Soft Reset: Undo Last Commit (Keep Local Changes)

To undo the last commit while keeping your local changes intact, use:

git reset --soft HEAD~1


This command removes the last commit but preserves all the changes in your staging area. It’s useful when you realize you need to modify your work before recommitting.

11. Hard Reset: Undo Last Commit (Remove Local Changes)

If you want to completely undo the last commit and discard all associated local changes, use:

git reset --hard HEAD~1


This command will erase the last commit and remove all uncommitted changes from your working directory. Use it carefully, as the changes will be permanently lost.