Git Cheat Sheet: A Quick Reference Guide to Essential Commands, Workflows, and Visualizing Your Git History with Git Graph in VS Code

M. Ilham Margatama
4 min readMar 14, 2023
Photo by Yancy Min on Unsplash

As someone who has been using Git for a while now, I know how overwhelming it can be to remember all the different commands and workflows. Git is an incredibly powerful tool, but it can also be very complicated if you don’t have a clear understanding of how it works. And now, with the Git Graph extension in Visual Studio Code, you can visualize your Git history and interact with your repository in new and exciting ways. In this Git cheat sheet, we’ll cover essential Git commands and workflows, as well as how to use Git Graph to improve your development workflow.

First and foremost, it’s important to understand what Git is and why it’s so useful. Git is a version control system that allows you to track changes made to your code over time. It’s particularly useful for teams working on a project together, as it allows each person to make changes to the code without interfering with others’ work. Git also allows you to roll back changes if something goes wrong, making it a valuable tool for developers.

Here are some of the most commonly used Git commands:

  1. git init: This command initializes a new Git repository in your current directory.
  2. git add: This command adds changes to the staging area, which prepares them to be committed to the repository.
  3. git commit: This command commits the changes you’ve made to the repository, along with a message describing what changes were made.
  4. git status: This command shows you the status of your repository, including any changes that have been made but not committed.
  5. git push: This command pushes your changes to a remote repository, typically hosted on a service like GitHub or GitLab.
  6. git pull: This command pulls changes from a remote repository into your local repository, allowing you to stay up to date with the latest changes.
  7. git clone: This command clones a remote repository to your local machine, allowing you to work on it locally.
  8. git branch: This command allows you to create, list, or delete branches in your Git repository. Branches are essentially separate lines of development that allow you to work on new features or fixes without affecting the main codebase. You can use the git branch command to create a new branch, switch between branches, or delete branches that are no longer needed.
  9. git checkout: This command allows you to switch between different branches in your repository. You can use the git checkout command followed by the name of the branch you want to switch to, and Git will automatically update your working directory to reflect the changes in that branch. This is particularly useful when you’re working on multiple features or fixes simultaneously and need to switch back and forth between them.
  10. git fetch: This command allows you to download changes from a remote repository without merging them into your local repository. When you use the git fetch command, Git will download all the changes that have been made to the remote repository since the last time you synced with it. This can be useful if you want to see what changes have been made without actually integrating them into your codebase.

These are just a few of the most commonly used Git commands, but there are many more that you can use depending on your specific needs. Git can be a complicated tool, but with practice and experience, you’ll become more comfortable with it over time.

In addition to these basic commands, there are also some useful tips and tricks that can help you use Git more efficiently. For example, you can use the — amend flag with the git commit command to make changes to your previous commit, rather than creating a new one. You can also use the — patch flag with the git add command to selectively add changes to the staging area, rather than adding everything at once.

Git Graph: Visualizing Your Git History

Visual Studio Code comes with a variety of Git integrations, including the Git Graph extension, which provides a visual representation of your Git history directly within the editor.

With Git Graph, you can see the branches, commits, and tags in your repository, as well as the relationships between them. This can be incredibly helpful when you’re trying to understand how your codebase has evolved over time, or when you’re trying to troubleshoot a particular issue.

Git Graph also allows you to interact with your Git repository directly from the editor. For example, you can create and switch between branches, create and apply patches, and even cherry-pick individual commits.

To use Git Graph, simply install the extension from the Visual Studio Code Marketplace and open it from the Git panel in the editor. You’ll be able to see your Git history in a clear, easy-to-understand format, making it easier than ever to stay on top of your codebase.

By using Git Graph in Visual Studio Code, you’ll be able to visualize and interact with your Git repository in new and exciting ways, making it easier than ever to manage your codebase and stay productive as a developer.

Overall, Git is an incredibly useful tool for developers, and understanding how to use it effectively is essential for working on complex projects. With this Git cheat sheet, you’ll be able to quickly reference some of the most commonly used commands and get up to speed with Git in no time. I love to hear your comment. Happy coding!

--

--