Getting started with git

Configuration

git config --global user.name "<username>"
git config --global user.email <email> # use private email set with git client
git config --global core.editor vim

Git can be congigured from system level to specific repository level.
--system option modify the file in /etc/gitconfig
--local option modify the file in .git/config

Generate SSH keypair

  • List existing keys in the ~/.ssh directory
  • Generate the ssh keypair
  • Add the key to the local ssh-agent
  • Add the ssh public key in the remote repository
  • ls -al ~/.ssh
    ssh-keygen -t ed25519 -C "<email>" # comment is optionnaly used to distinguish the key later
    Enter a file in which to save the key
    Type a secure passphrase
    ssh-keygen -p -f ~/.ssh/id_ed25519 # -p change or add the passphrase if needed while -f specify the private key file path
    eval "$(ssh-agent -s)"
    ssh-add ~/.ssh/id_ed25519
    cat ~/.ssh/id_ed25519.pub # copy the output into the git client

    I didn't get why my current shell can interact with the ssh-agent now.

    The process is running in the background while you capture its output...

    And I evaluate its environment variables in the shell... makes sense.

    When child processes, such as GUI applications, need to inherit the ssh-agent environment to work, exec ssh-agent <bash> can be used to replace the current shell for a new one under ssh-agent.

    Set up remote

    git init
    git remote add origin <remote_url>

    Already rebasing

    Rebase bad commits

    git stash -u
    git rebase -i HEAD~N
    git log --oneline -N
    git push --force-with-lease origin main
    git stash pop

    Redo a bad rebase

  • Identify in the reflog where to rewind the HEAD
  • Move away uncommited changes to allow git to rebase from a clean state
  • Reset the HEAD before the mistake
  • Rebase again
  • git reflog
    git stash -u
    git reset --hard HEAD@{N}
    git rebase -i HEAD~N
    git log --oneline -N
    git push --force-with-lease origin main
    git stash pop