This document covers commonly used commands for managing GitHub repositories, setting up SSH, and more.
- Setting Up a New Repository
- Cloning a Repository
- Using SSH with GitHub
- Basic Git Workflow
- Branching and Merging
- Viewing Repository Status
- Undoing Changes
- Syncing with Remote
- Go to GitHub and log in.
- Click the + button in the top-right corner and select New Repository.
- Fill in the repository name, description, and settings (e.g., public/private).
- Click Create Repository.
- Navigate to your project folder:
cd /path/to/your/project - Initialize a Git repository:
git init
- Add files to the staging area:
git add . - Commit the changes:
git commit -m "Initial commit" - Link the local repository to the remote GitHub repository:
git remote add origin https://github.com/username/repository-name.git
- Push the changes to GitHub:
git push -u origin main
git clone https://github.com/username/repository-name.gitgit clone git@github.com:username/repository-name.git-
Check for existing SSH keys:
ls -al ~/.ssh -
Generate a new SSH key (if needed):
ssh-keygen -t ed25519 -C "your_email@example.com"Press Enter to accept the default file location.
-
Set a passphrase (optional but recommended).
-
Copy the SSH key to your clipboard:
pbcopy < ~/.ssh/id_ed25519.pub
-
Go to GitHub > Settings > SSH and GPG keys > New SSH key.
-
Paste the key and save.
ssh -T git@github.comIf successful, you'll see: Hi username! You've successfully authenticated...
git statusgit add <file-name>Add all files:
git add .git commit -m "Your commit message"git push origin maingit pull origin maingit branch <branch-name>git checkout <branch-name>git checkout -b <branch-name>Switch to the main branch:
git checkout mainMerge the branch:
git merge <branch-name>git branch -d <branch-name>git loggit diffgit remote -vgit reset <file-name>git reset --hard HEADgit commit --amendgit fetch origingit pull --rebase origin maingit push --force origin main