Git Cheatsheet¶
Here is a summary of all the Git commands we will be using in this tutorial.
One Time Setup¶
Configuring Git¶
git config --global user.name "Your Name"
git config --global user.email "your_email@example.com"
Generating an SSH Key¶
ssh-keygen -t ed25519 -C "your_email@example.com"
cat ~/.ssh/id_ed25519.pub
On a New Project¶
Initializing a New Repository¶
git init
Adding a Remote Repository¶
git branch -M main
git remote add origin REPOSITORY_URL
git push -u origin main
git config pull.rebase false
Cloning a Repository¶
git clone REPOSITORY_URL
On an Existing Project¶
Checking the Status of Your Project¶
git status
Adding Files to the Staging Area¶
git add FILENAME # Adds a single file
git add * # Adds all files (works with new files too, not recommended)
git add -u # Adds all modified files (works with deleted files too, but not new files)
git add . # Adds all files (recommended)
Removing Files from the Staging Area¶
git rm FILENAME
Restoring Files from the Staging Area¶
git restore --staged FILENAME # After normal removal
git restore FILENAME # After "git rm FILENAME"
Committing Changes¶
git commit -m "Commit message"
Pushing Changes¶
git push
Pulling Changes¶
git pull