Exercise: 2.1 Git version control

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

    where Aaaa should be replaced with your actual project name

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/
  4. If you want, create .gitignore file in your project folder with following content:

    target/**
    logs/**

Commit and push changes

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

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

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.

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:

    git add -A
    git commit -m "Your message here"
  3. To get changes from remote repository and push back new changes from local repo enter command:

    git pull
    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 ~/git/
    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

Tagi:
Izveidojis Valdis Vītoliņš 2017-01-26 19:44
Pēdējais mainījis Valdis Vītoliņš 2017-08-01 09:16
 
Xwiki Powered
Creative Commons Attribution 3.0 Unported License