Mastering Git: A Comprehensive Cheat Sheet for Developers

Gulger Mallik
2 min readMar 12, 2024

--

Introduction

Version control is a cornerstone of modern software development, and Git stands out as one of the most widely adopted tools in this realm. Whether you’re a seasoned developer or just starting out, having a solid understanding of Git commands can significantly streamline your workflow and make collaboration smoother. In this article, we’ll delve into a comprehensive Git commands cheat sheet to help you navigate through version control with ease.

Source: GitHub Desktop

1. Setting Up Git:

  • git config --global user.name "Your Name": Sets the name you want attached to your commit transactions.
  • git config --global user.email "youremail@example.com": Sets the email you want attached to your commit transactions.
  • git init: Initializes a new Git repository in the current directory.
  • git clone <repository_url>: Clones a repository into a newly created directory.

2. Basic Commands:

  • git status: Shows the status of changes as untracked, modified, or staged.
  • git add <file>: Adds a file to the staging area.
  • git commit -m "Commit message": Records changes to the repository with a descriptive message.
  • git push: Pushes committed changes to a remote repository.
  • git pull: Fetches and merges changes from a remote repository to your local branch.
  • git fetch: Downloads objects and refs from another repository.

3. Branching and Merging:

  • git branch: Lists all local branches in the current repository.
  • git branch <branch_name>: Creates a new branch.
  • git checkout <branch_name>: Switches to the specified branch.
  • git merge <branch_name>: Merges changes from one branch into the current branch.
  • git branch -d <branch_name>: Deletes the specified branch.
  • git merge --abort: Aborts the current merge and restores the original state.

4. Advanced Commands:

  • git rebase <branch_name>: Reapplies commits on top of another base tip.
  • git cherry-pick <commit>: Picks a commit from another branch and applies it to the current branch.
  • git reset <file>: Unstages the file, but preserves its contents.
  • git stash: Temporarily shelves changes that are not ready to be committed.
  • git blame <file>: Displays the last modification to each line of a file, including the author and commit message.
  • git log: Shows the commit history.

5. Collaboration and Remote Repositories:

  • git remote -v: Lists all remote repositories.
  • git remote add <name> <url>: Adds a new remote repository.
  • git remote remove <name>: Removes a remote repository.
  • git push <remote> <branch>: Pushes changes to a remote repository.
  • git pull <remote> <branch>: Fetches changes from a remote repository and merges them into the current branch.

Conclusion

Mastering Git commands is essential for any developer looking to streamline their workflow and collaborate effectively. With this comprehensive cheat sheet, you’re equipped with the fundamental commands to navigate through version control seamlessly. Whether you’re working solo or as part of a team, Git empowers you to manage your codebase efficiently and with confidence. So, dive in, explore, and unleash the full potential of Git in your development journey.

--

--

Gulger Mallik
Gulger Mallik

Written by Gulger Mallik

Passionate software engineer sharing daily insights on coding, tech trends, and best practices. Let's explore the world of programming together!

No responses yet