0xnhl

git

/ Update
3 min read

Git is a free, open-source distributed version control system designed to track changes in source code during software development.
It was created by Linus Torvalds in 2005 for Linux kernel development, and has become the global industry standard, used by over 93% of developers.

GitHub is a cloud-based platform that uses Git to help developers store, manage, and collaborate on software projects.

Essential Commands#

  • git init: Initializes a new local Git repository.
  • git clone [url]: Downloads an existing repository from a remote server (like GitHub).
  • git add [file]: Adds changes in your working directory to your staging area.
  • git commit -m "[message]": Saves your staged changes as a permanent snapshot in the history.
  • git push: Sends your local commits to a remote repository.
  • git fetch: Fetches changes from remote repository and adds to the master branch.
  • git pull: Fetches and merges changes from a remote repository to your local machine.

Setup#

  • install git
  • Set git name and email.
  • Auth / Connect to GH : can be done via HTTPS / SSH

Configuration#

  1. Set your name:
    git config --global user.name "Your Name"
  2. Set your email:
    git config --global user.email "youremail@example.com"
  3. Set default branch name (recommended):
    git config --global init.defaultBranch main
  4. Show current config. (This is usually stored in .gitconfig file in the home directory)
    git config --list

SSH Auth#

SSH URLs provide access to a Git repository via SSH, a secure protocol. To use these URLs, you must generate an SSH keypair on your computer and add the public key to your account on GitHub. For more information, see Connecting to GitHub with SSH.

  1. Generate SSH key
    • ssh-keygen -t ed25519 -C "your_email@example.com"
    • give location to save
    • enter passphrase if needed
  2. Adding your SSH key to the ssh-agent
    • Start the ssh-agent in the background. : eval "$(ssh-agent -s)"
    • Add your SSH private key to the ssh-agent : ssh-add ~/.ssh/id_ed25519
  3. Add the SSH public key to your account on GitHub.
    • Copy the SSH public key to your clipboard : cat ~/.ssh/id_ed25519.pub
    • Go to Github Settings -> Access -> SSH and GPG keys.
    • Click New SSH key or Add SSH key.
    • In the “Title” field, add a descriptive label for the new key.
    • Select the type of key, either authentication or signing. For more information about commit signing, see About commit signature verification.
    • In the “Key” field, paste your public key.
    • Click Add SSH key.
    • If prompted, confirm access to your account on GitHub.
  4. Test SSH connection
    • ssh -T git@github.com
    • verify fingerprint
    • Then if you get this message : Hi USERNAME! You've successfully authenticated, but GitHub does not provide shell access. :: SUCCESS.

Tips#

  • Add .patch to the end of a github commit url to see details about that commit (Including author,author email, commit diffs).
  • To show change history of files: git log --follow -p file
git
https://nahil.xyz/vault/git/
Author Nahil Rasheed
Published at June 15, 2025
Disclaimer This content is provided strictly for educational purposes only.