Skip to content

Instantly share code, notes, and snippets.

@moazmohamed20
Created May 11, 2024 10:11
Show Gist options
  • Save moazmohamed20/4068f47e53d33b8b0677f349e7662dd7 to your computer and use it in GitHub Desktop.
Save moazmohamed20/4068f47e53d33b8b0677f349e7662dd7 to your computer and use it in GitHub Desktop.

Git Commands

Initialization

Warning

Replace moazmohamed20 with your username
Replace moazmohamed15@outlook.com with your email

git config --global init.defaultBranch main
git config --global user.name moazmohamed20
git config --global user.email moazmohamed15@outlook.com

Generate SSH Key

Warning

Replace moazmohamed15@outlook.com with your email

ssh-keygen -t rsa -b 4096 -C "moazmohamed15@outlook.com"

Connect to GitHub

Important

You have to Generate SSH Key first.

Display Public Key:

cat ~/.ssh/id_rsa.pub

Tip

For cmd:

type ~/.ssh/id_rsa.pub

Copy and Pase In:

GitHub -> Settings -> SSH ang GPG keys -> New SSH key -> Key type: Auth

Test Connection:

ssh -T git@github.com

Sign All Commits & Tags as Verified

verified-commit

Important

You have to Generate SSH Key first.

Display Public Key:

cat ~/.ssh/id_rsa.pub

Tip

For cmd:

type ~/.ssh/id_rsa.pub

Copy and Pase In:

GitHub -> Settings -> SSH ang GPG keys -> New SSH key -> Key type: Signing

Configure Git globally:

git config --global gpg.format ssh
git config --global tag.gpgsign true
git config --global commit.gpgsign true
git config --global user.signingkey ~/.ssh/id_rsa

Other Commands

Create Repository From Existing Project

echo "# MyRepo" > README.md
git init
git add README.md
git commit -m "Initial Commit"
git remote add origin git@github.com:username/MyRepo.git
git push origin <Local>

Aliases

git config --global alias.cfg "config --global"
git cfg alias.st "status"
git cfg alias.cm "commit -m"
git cfg alias.loge "log --oneline"
git cfg alias.branche "branch -vva"

Branches

git checkout -b fast-branch
git branch -m renamed-fast-branch
git push origin renamed-fast-branch

git branch new-branch
git checkout new-branch

git checkout main
git merge new-branch
git branch -d new-branch
git push origin main

Stash

git stash list
git stash clear
git stash save "Comment"

git stash pop stash@{0}
git stash apply stash@{0}
git stash drop stash@{0}
git stash show stash@{0}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment