https://www.digitalocean.com/community/tutorials/how-to-install-git-on-ubuntu-14-04
and other resources
INSTALL GIT WITH APT
$ sudo apt-get update
$ sudo apt-get install git
$ git –version
git version 1.9.1
But when you look at the github website, 1.9.1 is far from the latest release, so let’s install from latest release’s source code
INSTALL GIT FROM SOURCE
remove first the previous apt-get installed its
$ sudo apt-get remove git
remove also git-man liberror-perl packages that is related with old git
$ sudo apt-get autoremove
actually we did this step above, let’s do it again
$ sudo apt-get update
install git dependencies
$ sudo apt-get install build-essential libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip
go to https://github.com/git/git and follow these steps
- select Branch: master dropdown
- select Tags
- select the latest stable release without rc name: i.e. v2.6.3
- At the right of the page, right click Download ZIP or click Copy Link Location
now go to opt folder
$ cd /opt
paste the link to download the latest version as git zip file
$ sudo wget https://github.com/git/git/archive/v2.6.3.zip -O git.zip
$ sudo unzip git.zip
$ cd git-2.6.3/
let’s compile the package and install it
$ sudo make prefix=/usr/local all
$ sudo make prefix=/usr/local install
finally we have the latest git version
$ git –version
git version 2.6.3
UPGRADE GIT
since git is installed, to upgrade later just clone the repository and then build and install, this will overwrite the existing git
$ cd /opt/
$ sudo git clone https://github.com/git/git.git
the clone creates a git folder, go to git and build, install
$ cd /opt/git
$ sudo make prefix=/usr/local all
$ sudo make prefix=/usr/local install
TEST GIT BETWEEN CLIENT AND SERVER
Time to setup the git projects both on server and client. Server has user msen23 along with a password. We don’t use here any sort of ssh authorization
ON SERVER
let’s continue on server and create a test git project repository
$ cd /opt/
$ sudo mkdir git
$ cd git
$ sudo mkdir testing.git
$ cd testing.git
— bare creates a central storage repository, developers would then clone testing.git to create a local copy on their development machines, bare repo names should end with git like we did here for testing.git folder, this way it’s cloned to its original folder name: testing
$ sudo git init –bare
Initialized empty Git repository in /opt/git/testing.git/
let’s give the git folder and subfolders the same user authentication
$ cd /opt/
$ sudo chown -R msen23:staff git
FIRST CLIENT: GIT INIT
we’ll use git commands actively from client, so let’s create the git project accordingly
$ sudo mkdir -p /var/testing
$ sudo chown :staff /var/testing
$ sudo chmod 775 /var/testing
if ubuntu (make sure you have git on client according to your OS version)
$ sudo apt-get install git
let’s do the global settings to contain correct information when commit to git repo
$ sudo git config –global user.name “Mehmet Sen”
$ sudo git config –global user.email “mehmetsen80@gmail.com”
$ git config –list
user.name=“Mehmet
user.email=mehmetsen80@gmail.com
you can edit this new configuration file, correct it if needed
$ sudo vi ~/.gitconfig
[user]
name = Mehmet Sen
email = mehmetsen80@gmail.com
let’s go to the project folder and initialize the git
$ cd /var/testing
$ git init
Initialized empty Git repository in /private/var/testing/.git/
let’s create 3 different files
$ touch README random.hp random.cpp
now add all files and directories to the newly created git repository (you won’t see any output which means you are ok and watch out that there is a dot next to add)
$ git add .
let’s do our initial commit for the 3 files
$ git commit -m ‘initial commit’
[master (root-commit) 482bf1a] initial commit
3 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README
create mode 100644 random.cpp
create mode 100644 random.hpp
if you need to remove the remote origin
$ git remote remove origin
let’s add the remote origin to the ip
$ git remote add origin msen23@52.89.115.179:/opt/git/testing.git
finally push it
$ git push origin master
it asks password, after you type you will see that the 3 files are pushed
Counting objects: 3, done. Delta compression using up to 8 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 229 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To msen23@52.89.115.179:/opt/git/testing.git * [new branch] master -> master
USING GIT COMMANDS
let’s continue from the 1st client above
since everything is committed
$ git status
On branch master
nothing to commit, working directory clean
update README file
$ sudo vi README
README HERE ============
let’s recheck the status
$ git status
On branch master
Changes not staged for commit:
(use “git add …” to update what will be committed)
(use “git checkout — …” to discard changes in working directory)modified: README
no changes added to commit (use “git add” and/or “git commit -a”)
add a new file
$ sudo touch index.php
look status in a more compact way, M means modified, A means new file added to the staging area, ?? means hasn’t been tracked yet
$ git status -s or $ git status –short
M README ?? index.php
There are 2 columns for status indicators. The left hand column indicates that the file is staged and the right hand column indicates that it’s modified. The above M indicates that README file is modified in the working directory but not yet staged
let’s add the index.php
$ git add index.php
$ git status -s
M README A index.php
now update index.php file
$ sudo vi index.php
<?php
?>
echo "hello world";
$ git status -s
M README AM index.php
time to commit, -a allows to skip the staging
$ git commit -am “added new file index.php and update of README”
to lookup the git logs, it shows each committed snapshot which we have 2 snapshots here
$ git log
commit dea24f4d5827ad0f9cd775ab299eefede1582158
Author: Mehmet Sen <mehmetsen80@gmail.com>
Date: Wed Nov 11 11:49:03 2015 -0600added new file index.php and update of README
commit 482bf1a7fe77ac6729677ead6535e392ee0d4938
Author: Mehmet Sen <mehmetsen80@gmail.com>
Date: Wed Nov 11 10:13:29 2015 -0600initial commit
let’s checkout the 1st snapshot
$ git checkout 482bf1a7fe77ac6729677ead6535e392ee0d4938
when you list the folder, you’ll see that there is no index.php file created at the first commit
$ ls
README random.cpp random.hpp
so let’s go back to the master
$ git checkout master
Previous HEAD position was 482bf1a… initial commit
Switched to branch ‘master’
you see that now we have the latest committed files including index.php file
$ ls
README index.php random.cpp random.hpp
Finally let’s push it, enter password if asks
$ git push origin master
Counting objects: 4, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 399 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To msen23@52.89.115.179:/opt/git/testing.git
482bf1a..dea24f4 master -> master
2ND CLIENT: CLONING GIT PROJECT
let’s try a different way of working with remote git project, remember that we are still on the client
create first a git folder under var, we’ll clone later the git projects under this /var/git/ folder
$ sudo mkdir -p /var/git
$ cd /var/git/
$ sudo chown :staff /var/git
$ sudo chmod 775 /var/git
finally let’s clone it
$ sudo git clone msen23@52.89.115.179:/opt/git/testing.git
Cloning into 'testing'... The authenticity of host '52.89.115.179 (52.89.115.179)' can't be established. RSA key fingerprint is 62:a3:e4:e3:a0:c1:ee:48:53:7e:16:b5:12:8c:9a:ad. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '52.89.115.179' (RSA) to the list of known hosts. msen23@52.89.115.179's password: remote: Counting objects: 7, done. remote: Compressing objects: 100% (4/4), done. remote: Total 7 (delta 0), reused 0 (delta 0) Receiving objects: 100% (7/7), done. Checking connectivity... done.
check the cloned folder
$ ls
testing
let’s list the files under testing
$ cd testing
$ ls
README index.php random.cpp random.hpp
although git init creates a repo, most of the developers prefer to clone the git project from central repository, remember that the testing.git folder became just testing after it’s cloned
update index.php file, commit and push it
$ sudo vi index.php
<?php
?>
echo "This is the index.php file";
$ sudo git commit -am ‘update of index.php file’
$ sudo git push origin master
go to the other client
$ cd /var/testing/
you’ll see that index.php is still old
$ sudo vi index.php
<?php
?>
echo "hello world";
so let’s pull from central repo
$ sudo git pull origin master
* branch master -> FETCH_HEAD
Updating dea24f4..33398ad
Fast-forward
index.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
let’s look again our index.php file, it should have changed
$ sudo vi index.php
<?php
?>
echo "This is the index.php file";
3RD CLIENT: CLONING FROM PHPSTORM IDE
From above menu:
- VCS -> Checkout from Version Control->Git
- Clone Repository Dialog will appear. Type the following inputs
- Git Repository URL: msen23@52.89.115.179:/opt/git/testing.git
- Parent Directory: /private/var/git/
- Directory Name: testing
- Click Clone button
- Checkout From Version Control Dialog appears asking “Would you like to open the directory /private/var/git/testing?” -> Yes
- Open Project -> New Window
- you’ll see that your 4 files (index.php, random.cpp, random.hp and README) are opened in a new project folder called testing (/private/var/git/testing)