This is a cheatsheet with the most common commands in Git for the year 2024. Git Install 1
 2
 3
 4
 sudo add-apt-repository ppa:git-core/ppa
 sudo apt update
 sudo apt install git
 git --version
 
 1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 git config --global user.name "Xxxxxx"
 git config --global user.email "[email protected] "
 
 # Enable main as the default branch
 git config --global init.defaultBranch main
 
 # Enable colours
 git config --global color.ui auto
 
 # Check the configuration
 git config --list
 
Generate ssh key https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent 
 1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 ssh-keygen -t ed25519 -C "[email protected] "
 
 # save in:
 /home/user/.ssh/id_ed25519
 
 # start the ssh agent:
 eval "$(ssh-agent -s)"
 
 # add the new key in the agent we just startred:
 ssh-add ~/.ssh/id_ed25519
 
 # see the new public key:
 cat ~/.ssh/id_ed25519.pub
 
Using ssh to connect with GitHub:
https://docs.github.com/en/authentication/connecting-to-github-with-ssh/using-ssh-agent-forwarding 
Connect to Github Repo First initialization 1
 2
 3
 4
 5
 6
 7
 cd webdev/sites/myWebsite
 git init
 git add .
 git commit -m "first commit"
 git branch -M main
 git remote add origin [email protected] :xxxxxx/xxxxxx.git
 git push -u origin main
 
Connect to Remote 1
 2
 3
 4
 5
 6
 7
 git clone [email protected] :xxxxxx/xxxxxx.git
 
 # Restore Submodules (themes) if any:
 git submodule update --init --recursive
 
 git remote -v
 git remote show origin
 
Make Commits 1
 2
 3
 4
 git status
 git add file
 git commit -m "commit"
 git push -u origin main
 
Cover photo by Pawel Czerwinski  on Unsplash 
Licensed under CC BY-NC-SA 4.0 Last updated on Feb 04, 2024 11:23 CET