DEV Community

kabeer1choudary
kabeer1choudary

Posted on • Originally published at geekopsjab.blogspot.com

1

Git - Cheat Sheet: A Quick Guide to Git Commands

Git, the ubiquitous version control system, empowers developers to efficiently manage their codebase. Whether you're a Git novice or a seasoned pro, having a cheat sheet handy can be a game-changer. Let's explore a comprehensive Git cheat sheet to help you navigate your repositories with ease.

1. Setting Up Git:

  • Configure User Information:

     git config --global user.name "Your Name"
     git config --global user.email "your@email.com"
    
  • Initialize a Repository:

     git init
    

2. Basic Commands:

  • Clone a Repository:

     git clone <repository_url>
    
  • Check Repository Status:

     git status
    
  • Add Changes to Staging:

     git add <file_name>
    
  • Commit Changes:

     git commit -m "Your commit message"
    

3. Branching:

  • Create a New Branch:

     git branch <branch_name>
    
  • Switch to a Branch:

     git checkout <branch_name>
    
  • Merge Branches:

     git merge <branch_name>
    
  • Delete a Branch:

     git branch -d <branch_name>
    

4. Remote Repositories:

  • Add a Remote Repository:

     git remote add origin <repository_url>
    
  • Push to a Remote Repository:

     git push -u origin <branch_name>
    
  • Pull Changes from a Remote Repository:

     git pull origin <branch_name>
    

5. Undoing Changes:

  • Discard Changes in Working Directory:

     git checkout -- <file_name>
    
  • Undo the Last Commit:

     git reset --soft HEAD
    
  • Discard Changes in Staging:

     git reset <file_name>
    

6. Log and History:

  • View Commit History:

     git log
    
  • Show Changes in a Commit:

     git show <commit_hash>
    
  • Compare Branches:

     git diff <branch1> <branch2>
    

7. Tagging:

  • Create a Lightweight Tag:

     git tag <tag_name>
    
  • Create an Annotated Tag:

     git tag -a <tag_name> -m "Tag message"
    
  • Push Tags to Remote Repository:

     git push origin --tags
    

This Git cheat sheet serves as a quick reference, aiding you in mastering the essential commands for version control. Keep it handy on your desk or bookmarked in your browser for those moments when you need a quick Git command refresher. Happy coding!

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay