git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
-
Generate ssh key (if none exists)
ssh-keygen -t ed25519 -C "your_email@example.com"
or for rsa / legacy system
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
- Add passphrase when prompted (recommended)
-
Start the ssh-agent
eval "$(ssh-agent -s)"
May need to use different command -
Add ssh key to ssh-agent
ssh-add ~/.ssh/id_ed25519
or whatever the name of your ssh key is -
Copy ssh key
Linux:
cat ~/.ssh/id_ed25519.pub | xclip -selection clipboard
WSL:
cat ~/.ssh/id_ed25519.pub | clip.exe
-
Add ssh key to remote repository
- GitHub
- Go to SSH and GPG keys under "Access" in profile settings
- Paste in ssh key
- Add SSH key
- GitHub
-
Generate ssh key (if none exists)
ssh-keygen -t ed25519 -C "your_email@example.com"
or for rsa / legacy system
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
- Add passphrase when prompted (recommended)
-
Start the ssh-agent
eval "$(ssh-agent -s)"
May need to use different command -
If using Sierra 10.12.2 or later, setup ssh config
-
Check config exists
open ~/.ssh/config
-
If the file doesn't exist
touch ~/.ssh/config
-
Add to config:
Host github.com AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_ed25519
-
If no passphrase for key, you should omit the UseKeychain line
-
If you see usekeychain error, add an additional line to the configuration
IgnoreUnknown UseKeychain
-
-
Add ssh key to ssh-agent
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
- or whatever the name of your ssh key is
- If no passphrase for key, run without
--apple-use-keychain
-
Copy ssh key
pbcopy < ~/.ssh/id_ed25519.pub
-
Add ssh key to remote repository
- GitHub
- Go to SSH and GPG keys under "Access" in profile settings
- Paste in ssh key
- Add SSH key
- GitHub
- With a -m or -M option, the branch will be renamed to the argument after the option
git branch -m main
- -u option: after pushing your local branch with the -u option, this local branch will be automatically linked with the remote branch, and you can use git pull / push without any arguments
git push -u origin main
git remote -v
git remote set-url origin [url]
- origin is just the default local name for the remote repository, it can be changed
You can get the best of both worlds: rebase local changes before pushing to clean up your work, but never rebase anything that you’ve pushed somewhere.
git stash
git stash pop