Complete GitHub Commands Cheat Sheet
Whether you're just starting with Git or looking to streamline your workflow, this GitHub command cheat sheet provides all the essential commands you'll need. From setting up your environment to pushing changes to repositories, it's a one-stop guide to help you work efficiently with Git and GitHub. ✅ Setup and Configuration git config --global user.name "Your Name" — Set your Git username globally. git config --global user.email "your_email@example.com" — Set your Git email globally. git config --list — Display the current Git configuration settings. ssh-keygen -t ed25519 -C "your_email@example.com" — Generate a new SSH key for secure connections. ssh-add ~/.ssh/id_ed25519 — Add the generated SSH key to the SSH agent. ✅ Repository Commands git init — Initialize a new Git repository. git clone — Clone an existing repository to your local machine. ✅ Setting Up HTTPS and SSH Before pushing to GitHub, you need to set up authentication. Here's how: 1. Setting Up HTTPS: Go to your repository on GitHub. Click the Code button. Copy the HTTPS URL under the HTTPS tab. In your terminal, run: git remote add origin https://github.com/username/repo.git 2. Setting Up SSH: Generate an SSH key: ssh-keygen -t ed25519 -C "your_email@example.com" Copy the SSH key to your clipboard: cat ~/.ssh/id_ed25519.pub Go to GitHub > Settings > SSH and GPG keys > New SSH key. Paste the key and save. In the terminal, run: git remote add origin git@github.com:username/repo.git ✅ Pushing to GitHub via HTTPS and SSH Push Using HTTPS: # Stage the changes git add . # Commit the changes git commit -m "Your commit message" # Push to the remote repository via HTTPS git push https://github.com/username/repo.git main Push Using SSH: # Stage the changes git add . # Commit the changes git commit -m "Your commit message" # Push to the remote repository via SSH git push git@github.com:username/repo.git main ✅ Basic Commands git status — Check the status of the working directory and staging area. git add — Stage a specific file for commit. git add . — Stage all changes in the working directory. git commit -m "commit message" — Commit staged changes with a descriptive message. git log — View the commit history with full details. git log --oneline — View a summarized commit history. ✅ Branching and Merging git branch — List all branches in the repository. git branch — Create a new branch. git checkout — Switch to a specific branch. git checkout -b — Create and switch to a new branch in one command. git merge — Merge a branch into the current branch. ✅ Remote Repositories git remote -v — Display all remote repositories linked to the project. git remote add origin — Link a remote repository to the local repository. git push -u origin main — Push local changes to the main branch of the remote repository. git pull — Fetch and merge changes from the remote repository. git fetch — Fetch changes without merging. ✅ Undoing Changes git reset — Unstage a file but keep the changes. git reset --hard — Discard all changes in the working directory. git revert — Create a new commit that undoes the specified commit. ✅ Tagging git tag — List all tags in the repository. git tag — Create a new tag. git push origin — Push a specific tag to the remote repository. ✅ Stashing git stash — Temporarily save changes without committing them. git stash apply — Reapply stashed changes. git stash drop — Delete the last stash. ✅ Collaboration and Pull Requests git fork — Create a personal copy of a repository on GitHub. git pull request — Create a pull request for review. git merge --no-ff — Merge with a merge commit, preserving branch history. ✅ Viewing and Searching git diff — Show differences between the working directory and the staging area. git show — Display details of a specific commit. git blame — Show the last modification for each line of a file. With these commands, you're equipped to handle everything from basic Git operations to more advanced collaboration features. Bookmark this guide for quick reference, and you're all set to take full control of your projects on GitHub. Feel free to ask any questions!

Whether you're just starting with Git or looking to streamline your workflow, this GitHub command cheat sheet provides all the essential commands you'll need. From setting up your environment to pushing changes to repositories, it's a one-stop guide to help you work efficiently with Git and GitHub.
✅ Setup and Configuration
-
git config --global user.name "Your Name"
— Set your Git username globally. -
git config --global user.email "your_email@example.com"
— Set your Git email globally. -
git config --list
— Display the current Git configuration settings. -
ssh-keygen -t ed25519 -C "your_email@example.com"
— Generate a new SSH key for secure connections. -
ssh-add ~/.ssh/id_ed25519
— Add the generated SSH key to the SSH agent.
✅ Repository Commands
-
git init
— Initialize a new Git repository. -
git clone
— Clone an existing repository to your local machine.
✅ Setting Up HTTPS and SSH
Before pushing to GitHub, you need to set up authentication. Here's how:
1. Setting Up HTTPS:
- Go to your repository on GitHub.
- Click the Code button.
- Copy the HTTPS URL under the HTTPS tab.
- In your terminal, run:
git remote add origin https://github.com/username/repo.git
2. Setting Up SSH:
- Generate an SSH key:
ssh-keygen -t ed25519 -C "your_email@example.com"
- Copy the SSH key to your clipboard:
cat ~/.ssh/id_ed25519.pub
Go to GitHub > Settings > SSH and GPG keys > New SSH key.
Paste the key and save.
In the terminal, run:
git remote add origin git@github.com:username/repo.git
✅ Pushing to GitHub via HTTPS and SSH
- Push Using HTTPS:
# Stage the changes
git add .
# Commit the changes
git commit -m "Your commit message"
# Push to the remote repository via HTTPS
git push https://github.com/username/repo.git main
- Push Using SSH:
# Stage the changes
git add .
# Commit the changes
git commit -m "Your commit message"
# Push to the remote repository via SSH
git push git@github.com:username/repo.git main
✅ Basic Commands
-
git status
— Check the status of the working directory and staging area. -
git add
— Stage a specific file for commit. -
git add .
— Stage all changes in the working directory. -
git commit -m "commit message"
— Commit staged changes with a descriptive message. -
git log
— View the commit history with full details. -
git log --oneline
— View a summarized commit history.
✅ Branching and Merging
-
git branch
— List all branches in the repository. -
git branch
— Create a new branch. -
git checkout
— Switch to a specific branch. -
git checkout -b
— Create and switch to a new branch in one command. -
git merge
— Merge a branch into the current branch.
✅ Remote Repositories
-
git remote -v
— Display all remote repositories linked to the project. -
git remote add origin
— Link a remote repository to the local repository. -
git push -u origin main
— Push local changes to the main branch of the remote repository. -
git pull
— Fetch and merge changes from the remote repository. -
git fetch
— Fetch changes without merging.
✅ Undoing Changes
-
git reset
— Unstage a file but keep the changes. -
git reset --hard
— Discard all changes in the working directory. -
git revert
— Create a new commit that undoes the specified commit.
✅ Tagging
-
git tag
— List all tags in the repository. -
git tag
— Create a new tag. -
git push origin
— Push a specific tag to the remote repository.
✅ Stashing
-
git stash
— Temporarily save changes without committing them. -
git stash apply
— Reapply stashed changes. -
git stash drop
— Delete the last stash.
✅ Collaboration and Pull Requests
-
git fork
— Create a personal copy of a repository on GitHub. -
git pull request
— Create a pull request for review. -
git merge --no-ff
— Merge with a merge commit, preserving branch history.
✅ Viewing and Searching
-
git diff
— Show differences between the working directory and the staging area. -
git show
— Display details of a specific commit. -
git blame
— Show the last modification for each line of a file.
With these commands, you're equipped to handle everything from basic Git operations to more advanced collaboration features. Bookmark this guide for quick reference, and you're all set to take full control of your projects on GitHub.
Feel free to ask any questions!