Git cheat sheet

I'm a lazy coder who doesn't always use version control. When I do, it's almost always Git, but I struggle to remember beyond the most basic commands. This then invariably leads me into googling something like "git cheat sheet" and scroll through some complex looking html layout of a blog post someone created. Now that I've embraced Gemini, I've created a little cheat sheet for future reference. I'll keep updating it, so feel free to bookmark it:

Git cheat sheet

Meanwhile, I've included the current version down below...

Setup basic variables


git config --global user.name "first_name last_name"
git config --global user.email "email"

Clone repo


git clone path_to_repo

Add and commit files


git add file_name
git commit [-m "message"]

or



git commit -a [-m "message"]

Create repo from local files


cd folder
git init
git add .
git commit

Fork a github repo

Navigate to the target repo and on the top-right corner click fork.

Navigate to your fork of the repo and copy the clone URL.


git clone https://github.com/your_username/repo.git

Syncing a github fork

Navigate to the target repo and copy the clone URL.


cd fork_folder
git remote -v
git remote add upstream https://github.com/fork_username/repo.git
git remote -v
git fetch upstream
git checkout master
git merge upstream/master

Create and checkout a new branch


git branch branch-name
git checkout branch-name

or


git checkout -b branch-name