Prev
2. Preparation of Java project
Next
3. Java language syntax

Exercise: 2.1 Git version control

If necessary, review Version control systems

Practical exercise

Install git

To install git on your computer, enter command:

sudo apt-get install git

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 totes etc. in git with command, e.g.:

    git config --global core.editor leafpad
  3. Install meld and set it as default merge and diff tool for git:

    sudo apt-get install meld
    git config --global merge.tool meld
    git config --global diff.tool meld

Create bare Git repository on server

  1. Connect with SSH to the bcserver and create remote Git repository with commands:

    ssh student@bcserver
    mkdir /home/git/Aaaa
    cd /home/git/Aaaa
    git --bare init
    exit
    Aaaa should be replaced with your actual project name also in all places below!

Create non-bare Git project in your workspace

  1. Go to your project:

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

    git init
  3. Add remote repository to the project:

    git remote add origin ssh://student@bcserver/home/git/Aaaa/

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

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

    .classpath
    **/.~lock*
    *.log
    logs/**
    .metadata/**
    .project
    .settings/**
    target/**
    wbp-meta/**

Check configuration

help Run ConfigAndHelloTest1 unit test in package jtm.activity02 and check results for Test2Git entry.

Commit and push changes

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

cd ~/workspace/Aaaa
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/Aaaa
    git pull
    git add -A
    git commit -m "Your message here"
    git push

Checks

lightbulb Open http://bcserver/git/ and check that your project has recent content added into it.

Optional tasks

Install Egit plugin

  1. Install Egit plugin for Eclipse

Learn to use Git branches and merge tools

  1. Git branches and merging tools

Clone your project from server

  1. Open http://bcserver/git/ and check tree structure of your project
  2. Clone project from server in another folder to check it on your computer:

    cd ~/workspace
    git clone ssh://student@bcserver/home/git/Aaaa/ Aaaa1

    and check project in Eclipse

Use key exchange for SSH connections

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

Additional info

Prev
2. Preparation of Java project
Next
3. Java language syntax
  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.
Tags:
Created by Valdis Vītoliņš on 2018-04-05 14:59
Last modified by Valdis Vītoliņš on 2019-07-01 15:58
 
Xwiki Powered
Creative Commons Attribution 3.0 Unported License