Skip to main content

Command Palette

Search for a command to run...

Git Cheat Sheet

Published
β€’3 min readβ€’View as Markdown
Git Cheat Sheet
P

πŸš€ Passionate DevOps Engineer | AWS Enthusiast | Continuous Learner 🌟

πŸ‘‹ Hello! I'm Paresh Parde, a passionate and eager DevOps enthusiast ready to embark on a journey in the world of technology. With a solid foundation in both development and operations, I bring a fresh perspective and a hunger to learn and grow within the DevOps landscape.

Let's connect and explore how we can create impactful solutions together!πŸš€

Follow me on LinkedIn: https://www.linkedin.com/in/paresh-parde-544493232/

Introduction 🌟

Welcome to the ultimate Git cheat sheet! Whether you're new to version control or a seasoned developer, this guide will help you navigate Git's powerful commands and features. Let's dive in and make your Git workflow more efficient and enjoyable!

Setting Up Git πŸ› οΈ

  • Install Git

    Windows: Download and install from

      git-scm.com.
    

    macOS: Use Homebrew:

      brew install git.
    

    Linux: Use your package manager, e.g.,

      sudo apt-get install git (Debian/Ubuntu).
    
  • Configure Git

    Set your name:

      git config --global user.name "Your Name"
    

    Set your email:

      git config --global user.email "your.email@example.com"
    

    Check your configuration:

  •   git config --list
    

Basic Commands πŸ“š

  • Initialize a Repository

    Start a new repository:

      git init
    
  • Clone a Repository

    Copy an existing repository:

      git clone https://github.com/user/repo.git
    
  • Check Status

    See the current status of your working directory:

      git status
    

Working with Changes πŸ”„

  • Add Changes

    Stage changes:

      git add filename
    

    Stage all changes:

      git add .
    
  • Commit Changes

    Commit staged changes:

      git commit -m "Your commit message"
    
  • View Commit History

    Show commit history:

      git log
    

Branching and Merging 🌿

  • Create a New Branch

    Create a branch:

      git branch new-branch
    

    Switch to a branch:

      git checkout new-branch
    

    Create and switch to a new branch:

      git checkout -b new-branch
    
  • Merge Branches

    Merge a branch into your current branch:

      git merge branch-name
    
  • Delete a Branch

    Delete a branch:

      git branch -d branch-name
    

Remote Repositories 🌐

  • Add a Remote

    Add a new remote:

      git remote add origin https://github.com/user/repo.git
    
  • View Remotes

    List configured remotes:

      git remote -v
    
  • Push Changes

    Push to a remote repository:

      git push origin branch-name
    
  • Pull Changes

    Pull from a remote repository:

      git pull origin branch-name
    

Stashing Changes πŸ—ƒοΈ

  • Save Changes Temporarily

    Stash changes:

      git stash
    
  • Apply Stashed Changes

    Apply the latest stash:

      git stash apply
    
  • View Stashes

    List stashed changes:

      git stash list
    

Rebasing and Resetting πŸ”„

  • Rebase Branch

    Rebase your current branch onto another branch:

  •   git rebase branch-name
    
  • Reset Changes

    Reset your working directory:

      git reset --hard
    
  • Unstage Changes

    Unstage a file:

      git reset filename
    

Advanced Commands βš™οΈ

  • Cherry-Pick Commits

    Apply a specific commit from one branch to another:

      git cherry-pick commit-hash
    
  • Revert Commits

    Create a new commit that undoes a previous commit:

      git revert commit-hash
    
  • Show Differences

    Show changes between commits, branches, etc.:

      git diff
    

Helpful Tips & Tricks πŸ’‘

  • Aliasing Commands

    Create shortcuts for commonly used commands:

      git config --global alias.co checkout
    
  • Viewing File History

    See the history of a specific file:

      git log -- filename
    
  • Ignoring Files

    Create a file to specify files and directories Git should ignore.

      .gitignore
    

Conclusion πŸŽ‰

With this cheat sheet, you're now equipped to handle Git like a pro! From basic commands to advanced operations, Git offers powerful tools to manage your code efficiently. Keep this guide handy, and happy coding!

😊Happy Learning:)