APNIC 56 Network Automation tutorial
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Git and Gitlab lab

The goal here is to create a Gitlab account and push our code in from the server

Step 1 - Create Gitlab account

Go to gitlab.com and create your GitLab account.

https://gitlab.com/users/sign_up


Step 2 - Ensure git client is present on server

sudo apt install git

Note: This step is not needed for btNOG 10 workshop because VM image already contains git. Run this step incase you want to work on a new fresh machine which does not have your code.


Step 3: Configure git

Setup git with your username and email

git config --global user.name "Your name here"
git config --global user.email "email@domain.com"

Step 4: Setup SSH key access with Gitlab

Upload your existing SSH public key from the server on Gitlab account

cat ~/.ssh/id_rsa.pub

Paste your ssh public key into your GitLab user settings

  • Go to your GitLab user settings
  • Search for SSH Keys
  • Put your server public key on the page.
  • Add a title (like “aXX lab server” and hit add key.
  • In your server shell/terminal, type the following to test it.
ssh -T git@gitlab.com
  • If it says something below, it worked else you might have got the ssh key wrong.
Welcome to GitLab, @username!

If you do not see that message, contact instructor for help and do not proceed further.


Step 5: Start a new git repository

  1. Click on “New project” on the Gitlab homepage after logging in.
  2. Select “Create Blank project”
  3. Give project name as btnog10
  4. Keep visibility “Private”
  5. Uncheck “Initialize repository with a README”
  6. Click on create project

Step 6: Clone Gitlab project to local server

  1. Login to your server
  2. Go to gitlab project and inside the project click on “clone” button on top right
  3. Copy the output for clone with SSH
  4. On your server write git clone and paste the URL

(U) Thus full command will look like:

git clone git@gitlab.com:username/repository.git

Once cloned successfully, go inside the cloned directory


Step 7: Create a test file

Create a file name test.txt and write any text in it

touch test.txt
echo "This is my first code which will be tracked using git" > test.txt

Next, add this file in git tracking using command:

git add test.txt 

Next, commit this using

git commit -m "My first commit" 

And push this change using command

git push origin main

Ensure this pushed file is visible at Gitlab project by refreshing it.