Essential Git Commands Cheat Sheet for Developers

Listen to this Post

Featured Image
Tired of Googling Git commands every time you get stuck? This cheat sheet covers the most essential Git commands to streamline your workflow.

Basic Git Commands

1. `git init` – Initialize a new Git repository.

git init 

2. `git clone ` – Clone an existing repository.

git clone https://github.com/user/repo.git 

3. `git status` – Check the status of your working directory.

git status 

4. `git add ` – Stage changes for commit.

git add filename.txt 
git add .  Stage all changes 

5. `git commit -m “message”` – Commit staged changes.

git commit -m "Initial commit" 

6. `git push` – Push commits to a remote repository.

git push origin main 

7. `git pull` – Fetch and merge changes from a remote repository.

git pull origin main 

Branching & Merging

8. `git branch` – List all branches.

git branch 

9. `git checkout ` – Switch to a branch.

git checkout feature-branch 

10. `git merge ` – Merge a branch into the current one.

git merge feature-branch 

11. `git rebase ` – Reapply commits on top of another branch.

git rebase main 

12. `git stash` – Temporarily save uncommitted changes.

git stash 
git stash pop  Restore stashed changes 

13. `git log` – View commit history.

git log --oneline --graph 

You Should Know:

Advanced Git Commands for Power Users

  • Undo Last Commit
    git reset --soft HEAD~1 
    

  • Revert a Commit

    git revert <commit-hash> 
    

  • Find Changes Between Branches

    git diff branch1..branch2 
    

  • Delete a Remote Branch

    git push origin --delete branch-name 
    

  • Set Upstream Branch

    git push --set-upstream origin new-branch 
    

  • Check Remote Repositories

    git remote -v 
    

  • Force Push (Use with Caution!)

    git push --force 
    

What Undercode Say:

Git is a powerful tool for version control, and mastering these commands can drastically improve productivity. For cybersecurity professionals, Git is also used for tracking exploit code, managing security tools, and collaborating on open-source projects.

Related Linux & Windows Commands:

  • Linux:
    Find files modified in Git repo 
    find . -type f -mtime -7
    
    Grep through Git history 
    git grep "password" $(git rev-list --all) 
    

  • Windows (PowerShell):

    List Git branches sorted by last commit 
    git for-each-ref --sort=-committerdate refs/heads/
    
    Clean untracked files 
    git clean -fd 
    

Expected Output:

A well-structured Git workflow reduces errors and enhances collaboration. Bookmark this guide and integrate these commands into your daily development or cybersecurity tasks.

Prediction:

As DevOps and DevSecOps grow, Git will remain the backbone of version control, with more AI-powered Git assistants (like GitHub Copilot) automating repetitive tasks.

πŸ”— Relevant URLs:

References:

Reported By: Ashsau Tired – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass βœ…

Join Our Cyber World:

πŸ’¬ Whatsapp | πŸ’¬ Telegram