Git Commands Cheatsheet
Table of contents
Open Table of contents
Generate SSH Keys
Generate SSH keys using the RSA
algorithm.
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
After this command, two files will be generated in the following location by default: ~/.ssh/id_rsa
:
id_rsa
(your private key)id_rsa.pub
(your public key)
To copy the public key to clipboard, use the following command:
cat ~/.ssh/id_rsa.pub | pbcopy
Add or change Origin URL
# Add a new Origin
git remote add origin <url>
# Change the existing Origin
git remote set-url origin <new-url>
# View existing origins
git remote -v
Cherry Pick
cherry-pick
is a command that allows you to pick a specific commit from one branch to another.
git cherry-pick <commit_hash>
Git Rebase
rebase
is a command that allows you to reapply commits on top of another base tip.
# Rebase commits from the current branch on top of the selected branch
git rebase <branch_name>
# Enable interactive mode for more control
git rebase -i <branch_name>
# Continue the rebase process after resolving conflicts
git rebase --continue
# Abort the rebase process
git rebase --abort