The ultimate git cheat sheet to work at lightning speed

13 September 2021

The ultimate git cheatsheet
Photo by danroizer

I created my GitHub account in 2010, 2 years after the end of my studies. I was already a Linux user and I realized I was more productive using the terminal VS clicking everywhere. As a React Native developer, I switched to macOS and I still use the terminal for everything. Today I will share with you my setup to be super-efficient with git and GitHub.

This article provides insight into some of the best tools to use in your day-to-day workflow with the git command line and gets you started with a totally customized setup.

Setup

All UNIX-based operating system comes with a shell called Bash. There are alternatives to Bash that make using the terminal faster and more comfortable for web developers. One of the most popular is Oh My ZSH.

Installing Oh My ZSH is very simple. Simply run the following command and restart your terminal:

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

ZSH Plugins

ZSH allows you to extend built-in functionality by adding plugins. To enable a plugin, open your .zshrc file and add these:

# Useful oh-my-zsh plugins
plugins=(git gitfast common-aliases zsh-syntax-highlighting history-substring-search zsh-autosuggestions zsh-z)

Create new or download existing repository

Start using git on your project

# Create a new folder
take awesome_app

# Initialize a new repository
git init
git remote add origin git@github.com:username/repo.git

Review changes

Show commit history with various options:

# List commit history
glgg
glo
glol

git status can tell you if your folder has some modified files, but with Oh My ZSH we are using this shortcut

# Check the status of your files
gss

# See unstaged changes made to all files and inspect exactly what changed
gd

Commit changes

Saving your work is a 3-steps job. Check the status, git add all and write a commit message

# Check the status of your files
gss

# Stage all modified or deleted files,
gaa

# Make a commit
gcmsg 'feat: add history button closes #123'

Notice using "closes #123" in the commit message will automatically close the issue on GitHub

Pushing the changes to remote

# Push changes
gp

Bonus: change the previous commit

Sometimes you forgot to push something or you want to edit your previous commit.

gc! 	git commit -v --amend
gca! git commit -v -a --amend
gcan! git commit -v -a --no-edit --amend

# Push changes, forcing overrides
gp -f
Gravatar for dleuliette@gmail.com

Hi, I’m David, a french freelance developer working remotely. I’m the author of this blog, nice to meet you!

Subscribe?

Be the first to receive insightful articles and actionable resources that help you to elevate your skills across every touch point.