3.1 Git setup
Main steps
- Install git
- Set user data
- Create Git repository on server
- Create Git repository in your project
- Check configuration
- Commit and push changes
- Update local repository and push changes to remote repository
- Error solutions
- Optional tasks
- Additional info
Install git
(If it is not done already) install git client and meld comparison tools on your computer by entering commands:
sudo apt-get install gitInstall meld diff tool:
sudo apt-get install meld
Set user data
Set user data for Git version metadata with commands:
git config --global user.name "Name Surname"
git config --global user.email name.surname@example.comSet default editor for commit notes etc. in git with command, e.g.:
git config --global core.editor mousepadSet 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
Connect with SSH to the bcserver
ssh uXX@bcserverwhere uXX is your StudentId
(and bcerver is shorthand name created in /etc/hosts file for tools.odo.lv)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
Enter your initial password for the user:
uXX@bcserver's password:type your password and press Enter
Change password for your user, by entering command on bcserver:
passwdand enter required input:
Current password:
New password:
Retype new password:initial password given to you by teacher
your password
your passwordCreate remote Git repository:
mkdir JTM
cd JTM
git --bare init
exit
Create Git repository in your project
Go to your project:
cd ~/workspace/JTMInitialize local Git repository for the project:
git initAdd remote repository to the project:
git remote add origin ssh://uXX@bcserver/home/students/uXX/JTMor, 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
...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
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:
git add -A
git commit -m "Put yor comment here"
git push -u origin master
Update local repository and push changes to remote repository
- Use git status to see, what is changed comparing to last commit
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 pushIf 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 masterTo ensure that all your history from local repository is pushed to remote repository, run command:
git statusand 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:
- 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).
- Wait while teacher will disban your computer from blacklist.
Optional tasks
Use Egit plugin
- If your Eclipse doesn't have it already installed, install Egit plugin for Eclipse
- Learn How to use Egit plugin
- Learn how to use Git branches and merging tools
Clone your project from server
Clone project from server
cd ~/workspace
git clone ssh://uXX@bcserver/home/students/uXX/JTM JTM1where 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
- ^ 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.