The ultimate git cheat sheet to work at lightning speed
23 May 2022
I am releasing a book about the React Native ecosystem, which covers everything I wish I had known before I started working with this technology.
If you appreciate my work and would like to show your support, please check the Road to React Native.
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)
🚸 You will probably encounter this error if you relaunch "Warning: plugin zsh-syntax-highlighting not found". To fix the issue you can clone manually these repositories:
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/agkozak/zsh-z $ZSH_CUSTOM/plugins/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
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.