If it is not explicitly told in following recipe, setting up services are described for Ubuntu 16.04 server, but applications are described for Ubuntu 16.04 and/or Lubuntu 16.04 workstation. If you use different Ubuntu version or Linux distribution, settings as well as content, names and places of configuration files may be different!
Got it.

4. Git version control

If necessary, review Version control systems

Practical exercise

Install git

  1. (If it is not done already) install git command line and git GTK GUI on your computer, enter command:

    sudo apt-get install git
  2. Install meld diff tool:

    sudo apt-get install meld

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 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 bare Git repository on server

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

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

Create Git project in your workspace

  1. Go to your project:

    cd ~/workspace/Aaaaaa
  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/student/git/Aaaaaa/

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

    ...
    [remote "origin"]
    url = ssh://student@bcserver/home/student/git/Aaaaaa/
    ...
  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 GitTest1 unit test in package jtm.activity021 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/Aaaaaa
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/Aaaaaa
    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

    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://student@bcserver/home/student/git/Aaaaaa/

      where Aaaaaa is code of your project.
      To clone it in different folder add e.g. Aaaaaa1 at the end of previous command.

    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

  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 2020-05-28 13:48
Last modified by Valdis Vītoliņš on 2020-05-28 13:50
 
Xwiki Powered
Creative Commons Attribution 3.0 Unported License