Objective: Install Git on your development server, use it to track changes to files in a local repository, and undo a mistake. Then create a GitLab account, connect to it with the SSH key from Lab 7, and push your work to a private repository hosted on the internet.
Every administrator has done this: you edit a configuration file, something breaks, and you can't remember what the file looked like before. In Lab 9 you made a backup copy before you changed your network settings. That works for one file and one change. It doesn't tell you who changed a file, when, or why, and it doesn't keep every version.
Git does. It is a version control system: it keeps a history of every change to the files in a directory, with a note from whoever made each change. You can compare any two versions, and put a file back the way it was. Git was written in 2005 by Linus Torvalds, who we have discussed before to manage the source code of the Linux kernel. Today almost every software project, and a growing number of server configurations, live in Git.
Git works in two places:
| Where | What it is |
|---|---|
| Local repository | A directory on your server. Git keeps its whole history in a hidden .git directory inside it. No network or account needed. (Parts 1 to 5) |
| Hosted repository | A copy of the repository on a server on the internet, such as GitLab or GitHub. It is a backup, a way to work from more than one computer, and a place to share your work with others. (Parts 6 to 8) |
You will use the hosted repository you create today for the rest of the course, to keep notes and scripts from later labs.
Note: This lab is done on your development server, NOT your production server. Connect with SSH from a Terminal or PuTTY and log in as your own user. You will also need a web browser on your own computer for Parts 6 to 8.
Some steps give you every command. Others give you a Goal and ask you to work out the commands yourself. If you get stuck, open the hint. Once you have an answer, or if you are really stuck, open the solution and compare it with your own.
If you get stuck, check the Troubleshooting section at the end of this lab.
Check whether Git is installed. If you see command not found, install it with dnf, as you did with ethtool in Lab 9:
git --version
sudo dnf install -y git
git --version
git --version should now print something like git version 2.43.5. Your version may be a little different, and that is fine.
Note: You may see
yuminstead ofdnfin older guides. On RHEL 9, yum is just another name for dnf, and accepts the same options.
Every Git command starts with git, followed by a subcommand, such as git init or git commit. To see the most common ones:
git --help
Every change you save in Git is signed with a name and an email address. Set them once, for every repository you use on this server. Use your name, and the email address you will use for your GitLab account in Part 6, such as your UW email:
git config --global user.name "Your Name"
git config --global user.email "yourname@uw.edu"
git config --global init.defaultBranch main
git config --global --list
| Command | What it does |
|---|---|
git config --global user.name |
The name saved with each change you make. |
git config --global user.email |
The email address saved with each change. GitLab uses it to link your changes to your account. |
git config --global init.defaultBranch main |
Names the first branch in every new repository main. You will learn what a branch is in Part 2. |
git config --global --list |
Shows the settings you just made. |
--global saves the settings in ~/.gitconfig, a text file in your home directory. Look at it:
cat ~/.gitconfig
Note: Without
init.defaultBranch, Git names the first branch master, and prints a long hint every time you create a repository. Terms such as master and slave are being replaced across the IT industry, and GitLab and GitHub both name the first branch main. Setting it here means your local repositories match GitLab.
Git doesn't save a change the moment you make it. You choose what to save, and when. To do that, Git has three places a file can be:
| Place | What it is | Command that moves a file there |
|---|---|---|
| Working directory | The files you see and edit with ls, cat and Vim. |
You edit the file. |
| Staging area (the index) | A list of changes you have chosen to put in your next commit. | git add |
| Repository | The history. Each saved set of changes is a commit, with a message, an author, a date and a unique ID. | git commit |
A branch is a line of commits, one after another. In this lab you only use one branch, main.
Create a directory for your local repositories, and a repository called projects inside it. mkdir -p creates every directory in the path at once:
mkdir -p ~/git/local_repo/projects
cd ~/git/local_repo/projects
pwd
git init
ls -la
| Command | What it does |
|---|---|
git init |
Turns the current directory into a Git repository. It prints Initialized empty Git repository in /home/yourname/git/local_repo/projects/.git/ |
ls -la |
Shows the hidden .git directory. This is the repository: Git keeps every commit in here. |
Warning: Never edit or delete the files inside
.gityourself. If you delete.git, your files are still there, but their history is gone.
Watch what git status says between each step. It is the command you will use most, and it always tells you which of the three places your files are in:
git status
echo "This is the initial readme for a local git repository." > README.txt
cat README.txt
git status
git add README.txt
git status
git commit -m "initial version of README.txt" README.txt
git status
git log

| Command | What it does |
|---|---|
git status (first) |
No commits yet, and nothing to commit. The repository is empty. |
git status (after echo) |
README.txt is listed in red under Untracked files. It is in your working directory, but Git isn't tracking it yet. |
git add README.txt |
Adds the file to the staging area. |
git status (after git add) |
README.txt is now green, under Changes to be committed. |
git commit -m "..." README.txt |
Saves the staged change to the repository as a commit. -m is the message: a short note saying what you changed. |
git status (after git commit) |
nothing to commit, working tree clean. Every change is saved. |
git log |
Lists the commits, newest first, with their ID, author, date and message. Press q if it opens in a pager. |
The long string after commit in git log is the commit's ID, also called a hash. Yours is different. The author line shows the name and email you set in Part 1.
Goal: Create a file called linux_commands.txt with two lines: a heading, and one Linux command with a note about what it does. Add it to Git, commit it with a message, and show that your repository now has two commits.
README.txt: add, commit, then check with status and log.echo "Listing of common linux commands and useful options" > linux_commands.txt
echo "mkdir -p /path/to/files # this will create all the folders in the path" >> linux_commands.txt
cat linux_commands.txt
git add linux_commands.txt
git commit -m "initial version of linux_commands.txt"
git status
git log

The first echo uses > to create the file. The second uses >> to add a line to the end. If both used >, the second line would replace the first, and the file would only have one line.
This time there is no file name at the end of git commit. Without one, Git commits everything in the staging area. git log lists both commits, newest first.
Git really earns its keep when files change. In this part you change a file, see exactly what changed, and save it with a message written in Vim.
Add a line to README.txt, then ask Git what is different:
echo "This repository holds my notes from the ITFDN 140 course." >> README.txt
git status
git diff
| Command | What it does |
|---|---|
git status |
README.txt is listed as modified. Git already tracks it, so it is no longer untracked. |
git diff |
Shows what changed since the last commit. Lines starting with + were added, and lines starting with - were removed. Press q if it opens in a pager. |
git diff works like the diff command you used in Lab 8 and Lab 9, but it compares your file with the version in the repository. You don't need to make a backup copy first.
Stage the change, then run git commit without -m:
git add README.txt
git diff
git diff --staged
git commit
After git add, plain git diff shows nothing, because it only shows changes that are not staged yet. git diff --staged shows what is about to be committed.
Without -m, Git opens Vim so you can write a longer message. This is one of the tools from Lab 4 that opens Vim for you. The lines starting with # are notes from Git, and are left out of the message.
:wq and press Enter.If you quit without typing a message, Git cancels the commit with Aborting commit due to empty commit message. Nothing is lost. Your change is still staged, so run git commit again.
git log
git log --oneline
git show
| Command | What it does |
|---|---|
git log --oneline |
One line per commit: a short version of its ID, and its message. The short ID works anywhere a full ID does. |
git show |
Shows the newest commit: its message, and the changes it made, the same way git diff does. |
You now have three commits.
Goal: Add two more commands you have learned in this course, each with a short note, to linux_commands.txt. Before you commit, show exactly what you changed. Commit the change, then show your history with one line per commit. You should have four commits.
>>, never >, or you will replace the lines you already have. (If you do, Part 5 shows you how to get them back.)-m, or leave it out and write the message in Vim. Both work.echo "ls -la # list every file, including hidden ones, with details" >> linux_commands.txt
echo "ip -br address # one line summary of every network interface" >> linux_commands.txt
git diff
git add linux_commands.txt
git commit -m "add ls and ip to linux_commands.txt"
git log --oneline
git diff shows your two new lines, each with a + in front. git log --oneline shows four commits, newest first:
4c1e9a2 (HEAD -> main) add ls and ip to linux_commands.txt
8d03b77 add course description to README
ceb4f91 initial version of linux_commands.txt
f845a25 initial version of README.txt
Your IDs and messages are different. HEAD -> main means that you are on the main branch, and this is its newest commit.
Not every file in a directory belongs in Git. Backups, log files, and anything with a password or private key in it should never be committed, and especially never pushed to a server on the internet. Once a file is in a commit, it is in the history, even after you delete it.
A file called .gitignore tells Git which files and directories to leave out. Each line is a pattern, such as a file name, a directory name ending in /, or a wildcard such as *.log.
Create a directory called archive and put a copy of /etc/passwd in it. This stands in for a file you don't want in your repository:
mkdir ~/git/local_repo/projects/archive
cp /etc/passwd ~/git/local_repo/projects/archive
git status
Git notices the new directory and lists archive/ under Untracked files. Tell Git to ignore it:
echo "archive/" > .gitignore
cat .gitignore
git status

archive/ has gone from Untracked files. Now .gitignore is listed instead.
Question: Why is
.gitignoreitself listed as untracked? Should you commit it?
.gitignore is a new file, like any other, so Git lists it as untracked. Yes, commit it. Then anyone who copies your repository, including you on another computer, gets the same rules, and won't commit the files you meant to keep out. You will do this in Task 3.
Note the .gitignore in your README, and commit the README:
echo "Include a .gitignore file to avoid committing directories and files." >> README.txt
git add README.txt
git status
git commit -m "updated README with git ignore details"
git log

git status still lists .gitignore as untracked, because you only added README.txt.
Editors and administrators leave backup files behind, with names such as README.txt.bak.
Goal: Create a backup copy of README.txt called README.txt.bak. Add one line to .gitignore so that Git ignores every file whose name ends in .bak, not just this one. Then commit .gitignore, and show that git status is clean.
.gitignore already has one line. Which redirect adds a second?git status before and after you change .gitignore. Then add and commit it like any other file.cp README.txt README.txt.bak
git status
echo "*.bak" >> .gitignore
cat .gitignore
git status
git add .gitignore
git commit -m "add .gitignore for archive and backup files"
git status
ls -a
After the echo, README.txt.bak is no longer listed, and only .gitignore is. After the commit, git status says nothing to commit, working tree clean, even though ls -a still shows archive and README.txt.bak. They are there, but Git ignores them.
Every administrator has typed > when they meant >>, as you were warned in Lab 5 and Lab 7. Without Git, the old contents are gone. With Git, you can get back the version from your last commit.
Make the mistake on purpose. This echo uses >, so it replaces README.txt:
echo "oops" > README.txt
cat README.txt
git status
git diff
cat shows only oops. git diff shows every line you lost with a - in front, and oops with a +. Now look at what git status suggests: use "git restore
git restore README.txt
cat README.txt
git status
README.txt is back the way it was at your last commit, and git status is clean again.
Warning:
git restorethrows away every change you made to the file since your last commit. Git can only bring back what it has saved. That is why you should commit often.
Sometimes you notice the mistake after git add.
Goal: Replace linux_commands.txt with a single line, using >, and stage the change with git add. Then use the advice in git status to take the change back out of the staging area, and put the file back the way it was in your last commit. Show that git status is clean, and that linux_commands.txt has all its lines.
git status after git add. It tells you exactly which command takes a file out of the staging area.git status again: you need one more command, the one you just used for README.txt.echo "oops" > linux_commands.txt
git add linux_commands.txt
git status
git restore --staged linux_commands.txt
git status
git restore linux_commands.txt
git status
cat linux_commands.txt
| Command | What it does |
|---|---|
git restore --staged linux_commands.txt |
Takes the change out of the staging area. The broken file is still in your working directory. git status now lists it under Changes not staged for commit. |
git restore linux_commands.txt |
Puts the file in your working directory back to the version in your last commit. |
Notice that each step moves the change back one place, in the opposite direction from Part 2: from the staging area to the working directory, then out of the working directory.
So far your repository lives in one place: your development server. If that server is lost, so is your history. A hosted repository keeps a copy on the internet. We use GitLab in this course. GitHub works in much the same way.
Your development server talks to GitLab over SSH, with a key, just like it talks to your production server in Lab 7. You already have everything you need:
| You need | You have it from |
|---|---|
| A private key on your development server | The dev01 key, ~/.ssh/id_ed25519, from Lab 7, Part 6. |
| An agent holding that key | eval "$(ssh-agent -s)" and ssh-add, from Lab 7, Part 6. |
| The public key on the server you connect to | This time the server is GitLab, so you paste it into a web page instead of authorized_keys. |
Question: Do you need to create a new key pair for GitLab?
No. Each computer you connect from gets its own key pair. You are connecting from your development server, and it already has one: dev01. Copy the same public key to GitLab, just as you copied it to production. One private key can open as many servers as you like.
If ssh-keygen ever asks Overwrite (y/n)?, answer n. Overwriting your dev01 key would lock you out of everywhere it lets you in, including ssh localhost from Lab 9.
In your SSH session on your development server:
ls -l ~/.ssh
eval "$(ssh-agent -s)"
ssh-add
ssh-add -l
You should see id_ed25519 and id_ed25519.pub in ~/.ssh. ssh-add asks for your dev01 passphrase once, and ssh-add -l lists the key, ending in dev01.
Note: The agent only belongs to this SSH session, as you saw in Lab 7. Each time you log in and want to talk to GitLab, run
eval "$(ssh-agent -s)"andssh-addagain.
If you already have a GitLab account you want to use, sign in. Otherwise, create one at https://gitlab.com/users/sign_up. I recommend using your UW email address. It keeps your course work separate from your personal and work accounts. Use the same email you set with git config in Part 1.
Note your GitLab username. It is shown under your name, after the @, when you click your avatar.
On your development server, print your public key. Select the whole line, from ssh-ed25519 to dev01, and copy it:
cat ~/.ssh/id_ed25519.pub
In GitLab, click your avatar at the top of the left sidebar, then Edit profile (or Preferences).

In the menu on the left, choose Access and then SSH Keys, then Add new key.
Paste your public key into the Key box.
Title fills in from the key comment, dev01. Change it to something that says where the key lives, such as itfdn-rhel9-dev01. Titles are visible to other GitLab users, so don't put anything private in them.
Leave Usage type as Authentication & Signing. GitLab may fill in an Expiration date a year from now. You can leave it, or set it to the end of the quarter.
Click Add key.

Warning: Paste the public key, the
.pubfile. Never paste your private key into a web page.
When you logged in to production with a key, you got a shell. GitLab doesn't give you a shell, but it will tell you whether it recognized your key.
Goal: From your development server, open an SSH connection to gitlab.com as the user git, and get GitLab to greet you by your GitLab username. Then show that the key GitLab accepted is the key in your agent, by comparing fingerprints.
-T tells ssh not to ask for a terminal, because GitLab won't give you one.ssh asks you to trust its host key, as in Lab 2.ssh -T git@gitlab.com
The first time, ssh shows GitLab's host key fingerprint and asks Are you sure you want to continue connecting (yes/no/[fingerprint])? You can check the fingerprint against the list on GitLab's SSH host keys page. Type yes. Then GitLab answers and closes the connection:
Welcome to GitLab, @GITLAB_USERNAME!
Compare the fingerprints:
ssh-add -l
ssh-keygen -l -f ~/.ssh/id_ed25519.pub
Both print the same SHA256:... string. In GitLab, the SSH Keys page lists the same fingerprint for your itfdn-rhel9-dev01 key, and its Last used date has changed to today.
If you see Permission denied (publickey) instead, see Troubleshooting.
On GitLab, a repository lives inside a project. The project adds a web page for your files, and tools for working with others, but underneath it is a Git repository just like the one you made in Part 2.
In GitLab, click the + at the top of the right menu, choose New project/repository, then Create blank project.

Fill in the form:
| Field | Set it to |
|---|---|
| Project name | itfdn-140-inclass- followed by your development server username. Run echo itfdn-140-inclass-$USER on your server to see the exact name. |
| Project URL | Your GitLab username. |
| Project slug | Fills in from the project name. Check that it matches the project name exactly. |
| Project deployment target | No deployment planned, or leave it blank. |
| Visibility Level | Private. Only you can see it. |
| Initialize repository with a README | Unchecked. You will create the README yourself. |
Click Create project.

Note: Use your development server username, not your GitLab username, and use dashes, not underscores. Later labs change into this repository with
cd ~/git/gitlab/itfdn-140-inclass-$USER, so the name must match exactly.
GitLab shows a page saying The repository for this project is empty, with Command line instructions. Make sure SSH is selected under Add files. The section you need is Create a new repository.
You already set your name and email globally in Part 1, so you can skip Git local setup.
git clone copies a hosted repository to your server, and remembers where it came from. First make a directory for all your GitLab repositories.
mkdir -p ~/git/gitlab
cd ~/git/gitlab
Next we want to clone our Gitlab project onto our Development server. The git clone and change diretory (cd) commands are displayed under Create a new repository.
git clone git@gitlab.com:yourgitlabusername/itfdn-140-inclass-yourname.git
cd itfdn-140-inclass-$USER
pwd
git status
git remote -v

| Command | What it does |
|---|---|
git clone |
Creates the directory itfdn-140-inclass-yourname and copies the repository into it. It warns You appear to have cloned an empty repository, which is true, and fine. |
git status |
On branch main, No commits yet. |
git remote -v |
Lists the hosted repositories this one is linked to. The clone named it origin. You will see the same address twice: once for fetch (download) and once for push (upload). |
GitLab's instructions also include git switch --create main. You set init.defaultBranch main in Part 1, and git status already says On branch main, so you can skip that line.
GitLab shows a project's README.md file on the project's front page. The .md stands for Markdown: a plain text file with a few simple marks for formatting. For example, a line starting with # is a heading, and text between backticks is shown as code.
Create README.md with Vim:
vim README.md
Press i, and paste in this cheat sheet. Then press Esc, and type :wq:
# Git cheat sheet
The following is a brief Git cheat sheet written using Markdown syntax, to show some Markdown basics and Git basics.
## Git initialization
When creating a new git repository, create a folder and then run `git init` to set up the default folders.
```bash
git config --global user.name "your name"
git config --global user.email user@example.com
git config --global init.defaultBranch main
git init
git config --list
```
## Git commit and push
The following steps add a file to your git repo, commit the change and then push it to your hosted repository.
```bash
git add README.md
git commit -m "git commit message here"
git log
git push
git status
```
## Markdown tips
Markdown is the default markup language used by GitLab, GitHub and many other git based tools. Markdown lets you add formatting to a plain text file.
Headings start with the `#` symbol. One `#` is the largest heading, two `##` is the next smaller heading, and so on.
### Sample header using 3 # symbols
Now add, commit and push it. git push sends your commits to the hosted repository:
Note: Sometimes you need to set the gitlab target but our git clone set it for us earlier
git push --set-upstream origin main.
git add README.md
git commit -m "docs: add git and markdown tips to readme"
git push
git status
git log
| Command | What it does |
|---|---|
git push --set-upstream origin main |
Sends your main branch to origin, your GitLab project. --set-upstream links your local main to main on GitLab, so next time git push on its own is enough. You only need it for the first push. |
git status |
Your branch is up to date with 'origin/main'. GitLab has every commit you have. |
git log |
Your commit now shows (HEAD -> main, origin/main): your local branch and GitLab's copy point to the same commit. |
Go back to your project in GitLab, and refresh the page. Your README.md is listed, and its contents are shown below the file list, formatted. The # lines are now headings, and the commands are in grey code boxes.
`.
Click README.md, then History, to see the commit you pushed, with your name and message.
From now on, the cycle is always the same: change files, git add, git commit, then git push. In later labs you will add notes and scripts to this repository in exactly this way.
Later labs add notes files to this repository, and link to them from README.md. You will start that now.
Goal: In your GitLab repository on your development server, create a Markdown file called itfdn140-tips.md, with a heading and at least two tips you have learned so far in this course. Add a link to it at the end of README.md. Commit both files in one commit, and push. In GitLab, click the link in your README and check that it opens your tips.
Here is a start for your tips file:
# My admin cheat sheet from the UW ITFDN course
## bash
If you forget to put sudo in front of a command, type `sudo !!` on the next line. This runs sudo followed by the previous command.
A Markdown link looks like this: [text to show](file-name).
~/git/gitlab/itfdn-140-inclass-$USER, not in ~/git/local_repo/projects. git remote -v tells you whether a repository is linked to GitLab.README.md with Vim, or with echo and >>.git add can take more than one file name.git push on its own is enough.cd ~/git/gitlab/itfdn-140-inclass-$USER
vim itfdn140-tips.md
Paste the start above, add a second tip of your own, and save with :wq. For example:
## Redirects
`>` replaces a file. `>>` adds to the end of it. Use `>>` with authorized_keys and .gitignore.
Add the link to the end of README.md, then check, commit and push:
echo "" >> README.md
echo "## My notes" >> README.md
echo "" >> README.md
echo "[My ITFDN 140 tips](itfdn140-tips.md)" >> README.md
git status
git diff
git add README.md itfdn140-tips.md
git commit -m "docs: add tips file and link from README"
git push
git log --oneline
The empty echo "" lines matter: Markdown needs a blank line before and after a heading. In GitLab, your README now ends with a My notes heading and a link. Click it, and GitLab shows your tips, formatted.
Your repository now lives in two places. When someone, or you on another computer, changes the hosted copy, your local copy doesn't know until you ask.
Goal: In GitLab, edit itfdn140-tips.md in your browser, add a third tip, and commit the change there. Then, on your development server, bring that change into your local repository, and show it in your history.

cat itfdn140-tips.md doesn't show the new tip yet. git push sends commits to GitLab. Which command fetches them from GitLab?After you commit in GitLab:
cd ~/git/gitlab/itfdn-140-inclass-$USER
git status
git pull
cat itfdn140-tips.md
git log --oneline
| Command | What it does |
|---|---|
git status |
Still says up to date with 'origin/main'. It only knows what GitLab had the last time you talked to it. |
git pull |
Downloads the new commits from origin, and adds them to your local main. It lists the files that changed. |
git log --oneline |
The newest commit is the one you made in the browser, with the message from GitLab. |
Make a habit of running git pull before you start work in a repository, and git push when you finish. If you forget, and both copies have new commits, git push is refused. See Troubleshooting.
You have now:
git diff, read the history with git log, and written a commit message in Vim..gitignore.> mistake with git restore.ssh -T git@gitlab.com.| Command | What it does |
|---|---|
git init |
Turns the current directory into a repository. |
git clone <address> |
Copies a hosted repository to a new directory. |
git status |
Shows which files are untracked, modified or staged. |
git add <file> |
Stages a change for the next commit. |
git commit -m "message" |
Saves the staged changes as a commit. |
git diff, git diff --staged |
Shows unstaged, or staged, changes. |
git log, git log --oneline |
Shows the history. |
git restore <file> |
Throws away changes to a file since the last commit. |
git restore --staged <file> |
Takes a change out of the staging area. |
git push |
Sends your commits to the hosted repository. |
git pull |
Brings commits from the hosted repository into yours. |
Discuss these with others in class:
cp before you changed it. What does Git give you that a backup copy doesn't?git log --oneline. Will the messages make sense to you in three months?~/git/local_repo/projects repository has no origin. What would happen to it if your development server's disk failed?sshd and NetworkManager files from Labs 7 and 9, in Git. What would that give them?Q. git says "fatal: not a git repository (or any of the parent directories): .git".
A. You are not inside a repository. Run pwd, then cd into ~/git/local_repo/projects or ~/git/gitlab/itfdn-140-inclass-$USER. ls -a should show a .git directory.
Q. git commit says "Please tell me who you are" or "Author identity unknown".
A. You skipped Tell Git who you are. Run the two git config --global commands for user.name and user.email, then commit again.
Q. git commit opened a strange screen, and I can't get out.
A. That is Vim, waiting for a commit message. Press Esc, then type :q! and press Enter to cancel the commit. Then run git commit -m "your message" instead. Or, to write the message in Vim, see Write a commit message in Vim.
Q. git commit says "nothing added to commit but untracked files present".
A. You haven't staged anything. Run git add with the file name first, or put the file name at the end of git commit.
Q. ssh -T git@gitlab.com or git clone says "Permission denied (publickey)".
A. GitLab didn't accept your key. Check, in this order:
ssh-add -l. If it says Could not open a connection to your authentication agent, run eval "$(ssh-agent -s)" then ssh-add. If it says The agent has no identities, run ssh-add.~/.ssh/id_ed25519.pub, into GitLab? Compare the fingerprint from ssh-add -l with the one on GitLab's SSH Keys page.git@gitlab.com? Not as your own username.For more detail, run ssh -vT git@gitlab.com and look for the lines starting with Offering public key.
Q. ssh -T git@gitlab.com hangs, or says "Connection timed out".
A. Some networks block outgoing connections to port 22. GitLab also accepts SSH on port 443, at altssh.gitlab.com. Create or edit ~/.ssh/config on your development server, and add these lines:
Host gitlab.com
Hostname altssh.gitlab.com
Port 443
User git
Then set its permissions with chmod 600 ~/.ssh/config, and run ssh -T git@gitlab.com again. You will be asked to trust a new host key once.
Q. git push says "error: src refspec main does not match any".
A. You have no commits on main yet. Run git status and git log. Commit at least one file, then push again.
Q. git push says "Updates were rejected because the remote contains work that you do not have locally".
A. Someone, perhaps you in the GitLab web page, committed to GitLab since your last git pull. Run git pull first, then git push again. If git pull opens Vim with a Merge branch message, save it with :wq.
Q. git push says "fatal: The current branch main has no upstream branch".
A. This is your first push from this repository. Run git push --set-upstream origin main. After that, git push on its own works.
Q. My project is called something different from itfdn-140-inclass-$USER.
A. Later labs cd into ~/git/gitlab/itfdn-140-inclass-$USER. In GitLab, open your project, then Settings -> General. Change the Project name under Naming, topics, avatar, and the Path under Advanced -> Change path. Then, on your server, rename your local directory with mv, cd into it, and point it at the new address with git remote set-url origin, followed by the new git@gitlab.com:... address from your project's Code button. Check with git remote -v and git pull.
Q. I deleted the .git directory by mistake.
A. The history of a local-only repository is gone, but your files are still there. Run git init, git add . and git commit to start again. For your GitLab repository, push everything you can first, then move the directory aside and git clone it again.
If you can't solve a problem, post it in this week's Teams channel, or reach out by email for help.
Lab complete