Git Cheat Sheet - 50 Git Commands You Should Know
Git Cheat Sheet - 50 Git Commands You Should Know
This change history lives on your local machine and lets you revert to a previous version of your
project with ease in case something goes wrong.
Git makes collaboration easy. Everyone on the team can keep a full backup of the repositories
they're working on on their local machine. Then, thanks to an external server like BitBucket,
GitHub or GitLab, they can safely store the repository in a single place.
This way, different members of the team can copy it locally and everyone has a clear overview of all
changes made by the whole team.
Git has many different commands you can use. And I've found that these fty are the ones I use the
most often (and are therefore the most helpful to remember).
So I have written them down and thought it'd be nice to share them with the community. I hope you
nd them useful – Enjoy.
How to check your Git configuration: Forum Donate
git config -l
git init
git add .
This command will show the status of the current repository including staged, unstaged, and
untracked les.
git status
A commit message is made up of a short summary of changes, an empty line, and a full description
of the changes after it.
git commit
git log
Forum Donate
changes in Git:
This command shows the commit's history including all les and their changes:
git log -p
Replace commit-id with the id of the commit that you nd in the commit log after the word commit.
We can call diff with the --staged ag to see any staged changes.
git diff
git diff all_checks.py
git diff --staged
git rm filename
!!Note!!: xing up a local commit with amend is great and you can push it to a shared repository
after you've xed it. But you should avoid amending commits that have already been made public.
By default, you have one branch, the main branch. With this command, you can create a new
branch. Git won't switch to it automatically – you will need to do it manually with the next
command.
git remote -v
git pull
git branch -r
How to fetch remote repo changes in Git: Forum Donate
git fetch
Git Rebase can get really messy if you don't do it properly. Before using this command I suggest that
you re-read the of cial documentation here
Forum Donate
How to run rebase interactively in Git:
Learn to code — free 3,000-hour curriculum
You can run git rebase interactively using the -i ag.
It will open the editor and present a set of commands you can use.
git push -f
Forum Donate
Thanks for reading! By the way, I am Fabio, a full-stack web developer and teacher, and certi ed
professional in IT automation with Python. If you nd this cheat sheet useful, surely you will nd
something interesting also on my YouTube channel. You can subscribe here.
Fabio Pacific
Hi! I am Fabio a full-stack web developer, teacher and certi ed professional in IT automation with Python. I enjoy
sharing knowledge, write Python scripts and, build web apps with Laravel.
If you read this far, tweet to the author to show them you care. Tweet a thanks
Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000
Forum Donate
people get jobs as developers. Get started
Learn to code — free 3,000-hour curriculum
freeCodeCamp is a donor-supported tax-exempt 501(c)(3) nonpro t organization (United States Federal Tax Identi cation Number: 82-
0779546)
Our mission: to help people learn to code for free. We accomplish this by creating thousands of videos, articles, and interactive coding lessons -
all freely available to the public. We also have thousands of freeCodeCamp study groups around the world.
Donations to freeCodeCamp go toward our education initiatives, and help pay for servers, services, and staff.
Trending Guides
Our Nonpro t
About Alumni Network Open Source Shop Support Sponsors Academic Honesty Code of Conduct Privacy Policy