Git and SSH Notes

20 Nov 2025

Git and SSH Notes

Notes, mainly for working on sourcehut. I keep forgetting some of these commands and it’s nice to have a reference.

SSH

Start the SSH process

$ eval "$(ssh-agent -s)"

Key Location

Typically stored at ~/.ssh/

Add a Key to Current Session

$ ssh-add ~/.ssh/KEY_NAME

Git

Pushing a new repo to git.sr.ht

Sourcehut repositories have URLs like:

git@git.sr.ht:~USERNAME/REPOSITORY_NAME

In git, create a new remote:

git remote add SHORT_NAME URL

Create a new repository, add files to it, etc and run git init. Then, push it to the remote:

git push SHORT_NAME BRANCH_NAME 

Don’t forget to set to track the remote branch:

git branch --set-upstream-to=origin/main main

Full example:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/keyname
mkdir sonya
cd sonya 
echo "Diabetes simulator">README.md
git init 
git add --all
git commit -m "initial commit"
git remote add origin git@git.sr.ht:~freestatelabs/sonya
git push origin main
git branch --set-upstream-to=origin/main main

Result:

Initialized empty Git repository in ~/sonya/.git/
[main (root-commit) 63caa53] initial commit
 1 file changed, 1 insertion(+)
 create mode 100644 README.md
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 229 bytes | 229.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
remote: 
remote:         NOTICE
remote: 
remote:         You have pushed to a repository which did not exist. ~freestatelabs/sonya
remote:         has been created automatically. You can re-configure or delete this
remote:         repository at the following URL:
remote: 
remote:         https://git.sr.ht/~freestatelabs/sonya/settings/info
remote: 
remote: Default branch updated to main
To git.sr.ht:~freestatelabs/sonya
 * [new branch]      main -> main
branch 'main' set up to track 'origin/main'.

Current local branch has no upstream branch

Git does warn you of this and tell you how to fix it.

You’ve made a new branch and want to send it to the remote host.

 git push --set-upstream origin BRANCH_NAME