Note, that this recipe is not updated long time and could be outdated!
Got it.

4. Git version control

If necessary, review Version control systems

And notes about practical exercise

Practical exercise

Set user data

  1. Set user data for Git version metadata with commands:

    git config --global user.name "Name Surname"
    git config --global user.email name.surname@example.com
  2. Set default editor for commit notes etc. in git with command, e.g.:

    git config --global core.editor mousepad
  3. Set meld as default merge and diff tool for git:

    git config --global merge.tool meld
    git config --global diff.tool meld

Create Git repository on server

Use your StudentId in estudijas.lu.lv as username and initial password DatZ4019-2023-StudentId

  1. Connect with SSH to the bcserver

    ssh uXX@bcserver

    where uXX is your StudentId
    (and bcerver is shorthand name created in /etc/hosts file for tools.odo.lv)

  2. Accept server key fingerprint:

    The authenticity of host 'bcserver (<no hostip for proxy command>)' can't be established.
    ECDSA key fingerprint is SHA256:EfeSv9IS82KmbOHismH1JPkqC/j0fxvoe5GK1jR2KVY.
    Are you sure you want to continue connecting (yes/no/[fingerprint])?

    type yes

  3. Enter your initial password for the user:

    uXX@bcserver's password:

    type your password and press Enter

    Don't be confused, that password is not shown as stars/circles/whatever. It is accepted without any visible feedback.

  4. Change password for your user, by entering command on bcserver:

    passwd

    and enter required input:

    Current password:
    New password:
    Retype new password:

    initial password given to you by teacher
    your password
    your password

    Projects for users with default password will not be checked!

  5. Create remote Git repository:

    mkdir JTM
    cd JTM
    git --bare init
    exit

Create Git repository in your project

  1. Go to your project:

    cd ~/workspace/JTM
  2. Initialize local Git repository for the project:

    git init
  3. Add remote repository to the project:

    git remote add origin ssh://uXX@bcserver/home/students/uXX/JTM

    or, if you want to change settings, open .git/config file in the project and change settings:

    ...
    [remote "origin"]
    url = ssh://uXX@bcserver/home/students/uXX/JTM
    ...
  4. Create .gitignore file in your project folder with following content:

    .classpath
    .idea/**
    *.iml
    **/.~lock*
    *.log
    logs/**
    .metadata/**
    .project
    .settings/**
    doc/**
    lib/**
    target/**
    wbp-meta/**

Check configuration

help Run GitTest1 unit test in package jtm.activity031 and check results.

Commit and push changes

All changes can be commited to local repository and pushed to remote repository using following commands1:

cd ~/workspace/JTM
git add -A
git commit -m "Put yor comment here"
git push -u origin master

Update local repository and push changes to remote repository

  1. Use git status to see, what is changed comparing to last commit
  2. Add all changes to your local repository and push them to remote repository:

    cd ~/workspace/JTM
    git pull
    git add -A
    git commit -m "Your message here"
    git push
  3. If you have local git repository with different history than remote project, and know, that local project is OK, then you can forcefully push your project to the server by adding -f switch, e.g.:

    git push -f origin master
  4. To ensure that all your history from local repository is pushed to remote repository, run command:

    git status

    and chek that it returns lines:

    Your branch is up to date with 'origin/master'.

    nothing to commit, working tree clean

Error solutions

Connection timeout

If you have connection timeout:

  1. Open https://www.whatismyip.com/ and check what is public IP address for your computer. Notify teacher (say it and write IP address in Zoom chat).
  2. Wait while teacher will disban your computer from blacklist.

Optional tasks

Use Egit plugin

  1. If your Eclipse doesn't have it already installed, install Egit plugin for Eclipse
  2. Learn How to use Egit plugin
  3. Learn how to use Git branches and merging tools

Clone your project from server

  1. Clone project from server

    cd ~/workspace
    git clone ssh://uXX@bcserver/home/students/uXX/JTM JTM1

    where JTM is code of your current project, and JTM1 is different name of your newly cloned project.

Use key exchange for SSH connections

If you are tired of writing password for each push, you can enable SSH key exchange by following these instructions:

Additional info

  1. ^ origin is remote repository name, but master is branch mapping (shortened from master:master) from local to remote repository
    -u switch will set master branch of local repository as a default for pushing to remote repository, so after that simple git push and git pull can be used.

  

Created by Valdis Vītoliņš on 2020-05-28 10:48
Last modified by Valdis Vītoliņš on 2021-04-13 14:31
 
Xwiki Powered
Creative Commons Attribution 3.0 Unported License