Skip to main content

GIT & SSH Snippets

sudo apt install git

git config --global user.name FooBar
git config --global user.email foo@bar.ch

# create new ssh key pair

ssh-keygen

cat ~/.ssh/id_rsa.pub

Restore SSH Keys 1

  1. Change the file permission
sudo chown user:user ~/.ssh/id_rsa*
sudo chmod 600 ~/.ssh/id_rsa
sudo chmod 644 ~/.ssh/id_rsa.pub
  1. (Re-)Start the ssh-agent
exec ssh-agent bash
  1. Add your SSH private key to the ssh-agent
ssh-add ~/.ssh/id_rsa

Forward ssh-agent from Windows to WSL2

  1. Ensure the optional feature OpenSSH Client (System > Optional Features) is installed
  2. Make sure the OpenSSH Authentication Client runs and starts automatically on restart
    1. Open Services (Dienste)
    2. Find the service and set the starttype to automatic.
  3. Add the ssh keys to C:\Users\<username>\.ssh and then run ssh-add .ssh\id_rsa
  4. Done 🥳

Ignore changes from tracked files

Ignore all further changes, but you don't want git to remove current file from the repository:

git update-index --assume-unchanged <file>

... and reenable it again

git update-index --no-assume-unchanged <file>

Create new Repo with main Branch

echo "# asdfghjhgfdsa" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin git@github.com:lebalz/<reponame>.git
git push -u origin main

Git Submodules

Sync Submodule

In order to add a Git submodule, use the git submodule add command and specify the URL of the Git remote repository to be included as a submodule.

git submodule add <remote_url> <destination_folder>

git submodule add https://github.com/project/project.git vendors

Pull Submodule

To pull a Git submodule, use the git submodule update command with the –init and the –recursive options.

git submodule update --init --recursive

Sync

In order to update an existing Git submodule, you need to execute the git submodule update with the –remote and the –merge option.

git submodule update --remote --merge

Footnotes

  1. Source: 👉 Snippet by Colematt