What you end up with
~/notes/ the working directory
.git/ history, branches, repository settings — don't touch by hand
.gitignore what git doesn't see: .env, node_modules/, logs
README.md
github.com/example-user/notes the remote repository "origin", accessed with an SSH key
Setup
Install git
Where How Version Ubuntu 24.04 sudo apt install git2.43 Ubuntu 26.04 sudo apt install git2.53 Windows Git for Windows from git-scm.com, or winget install Git.Git2.55 as of October 2026 macOS xcode-select --installorbrew install gitApple’s lags behind, Homebrew’s is current The Git for Windows installer asks about line endings. The default answer (“Checkout Windows-style, commit Unix-style”) turns on
core.autocrlf=true— a trap for scripts headed to a server (Line endings in .gitattributes).git --version # git version 2.55.0.windows.5Introduce yourself
git config --global user.name "example-user" git config --global user.email "[email protected]" git config --global init.defaultBranch mainName and email go into every commit and are visible to anyone who can see the repository. To keep your personal email private, GitHub gives you an
…@users.noreply.github.comaddress: it’s in the account settings under “Emails”, and commits with it are still linked to your account.init.defaultBranch main— without this line git 2.x names the first branchmasterand shows a 13-line hint; in git 3.0 the default becomesmain. Other settings — ~/.gitconfig block by block.Create the repository
mkdir ~/notes && cd ~/notes git init # Initialized empty Git repository in /home/me/notes/.git/Everything git knows about this directory is in
.git/. Without.gitthere’s no history: delete it and the files stay, but the history is gone.First of all — .gitignore
Before the first
git add, decide what must never get into the repository:# .gitignore .env *.key node_modules/ dist/ *.log .DS_Store Thumbs.db.gitignoreonly affects files git doesn’t track yet. A.envthat made it into a commit won’t be removed from history by a line in.gitignore(.gitignore and a tracked file), and if it holds a password, you’ll have to change it (A secret in a commit). Ready-made lists for each language and framework are at github.com/github/gitignore.The first commit
echo "# Notes" > README.md git status # On branch main # # No commits yet # # Untracked files: # (use "git add <file>..." to include in what will be committed) # .gitignore # README.mdUntrackedmeans git sees the files but doesn’t track them. Put them in the index and commit:git add .gitignore README.md git commit -m "README and .gitignore" # [main (root-commit) 6f203cf] README and .gitignore # 2 files changed, 9 insertions(+) # create mode 100644 .gitignore # create mode 100644 README.md6f203cfis the start of the commit’s hash; any command can refer to the commit by it.The SSH key — into GitHub
The key from SSH keys will do. Add the public half,
~/.ssh/id_ed25519.pub, to GitHub: Settings, SSH and GPG keys, New SSH key, type Authentication Key. Check without git:ssh -T [email protected] # Hi example-user! You've successfully authenticated, but GitHub does not provide shell access.On the first connection
sshasks about thegithub.comkey: the ED25519 fingerprint isSHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU, published in GitHub’s documentation (Server fingerprint).An empty repository on GitHub, and push
On GitHub, create a repository called
notes— empty: no README,.gitignoreor license. Otherwise it has its own history, and the firstpushgets refused (see “If it doesn’t work”). Take the SSH URL, not HTTPS:git remote add origin [email protected]:example-user/notes.git git push -u origin main # To github.com:example-user/notes.git # * [new branch] main -> main # branch 'main' set up to track 'origin/main'.originis the conventional name for the remote repository.-ulinks the localmaintoorigin/main: from then on, plaingit pushandgit pullare enough.The daily loop
git status # what changed git diff # line by line: what exactly git add -p # into the commit piece by piece, with a prompt for each git commit -m "traefik: readTimeout 300s — uploads over a minute were cut off" git pushgit diffbefore committing is your last chance to notice something extra riding along: a password, a debug line, someone else’s file. The message says what and why; “fix” and “changes” will say nothing in a month (Everyday git).A second computer
git clone [email protected]:example-user/notes.git cd notes git log --oneline -3 # 6f203cf (HEAD -> main, origin/main) README and .gitignoreBefore working,
git pull; after,git push. Forgotpulland already committed — Branches in git.
If it doesn’t work
error: src refspec main does not match any
- Cause
- The repository has no commits yet, or the branch is called
masterwhile you pushmain. - Fix
git branch --show-currentshows the name; no commits —git commitfirst. To rename:git branch -m main.
fatal: refusing to merge unrelated histories
- Cause
- The GitHub repository was created with a README or a license — it has its own history, unrelated to yours.
- Fix
- Once:
git pull origin main --allow-unrelated-histories, resolve the conflicts,git push. Next time, create an empty repository on GitHub.
remote: Support for password authentication was removed on August 13, 2021.
- Cause
- The repository URL is
https://…, and git asks for your account password, which GitHub won’t accept. - Fix
- Switch to SSH:
git remote set-url origin [email protected]:example-user/notes.git.
error: remote origin already exists.
- Cause
git remote addfor a name that already exists — for example, you repeated the command with a corrected URL.- Fix
git remote set-url origin <url>, andgit remote -vto check.
nothing added to commit but untracked files present
- Cause
- The files are new and weren’t added to the index:
git commitcommits only the index. - Fix
git add <file>orgit add ., check withgit status, thengit commit.
How to check
The local branch is linked to GitHub and nothing is behind:
git status -sb
# ## main...origin/main
git remote -v
# origin [email protected]:example-user/notes.git (fetch)
# origin [email protected]:example-user/notes.git (push)
## main...origin/main without [ahead 1] or [behind 2] means you and GitHub have the same thing. A URL starting
with git@ means you go over SSH, and no password will be asked.