GIT is a distributed revision control and source code management (SCM) system with an emphasis on speed, initially designed and developed by Linus Torvalds for Linux kernel development; it has since been adopted by many other projects.
Every GIT working directory is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server. It is free software distributed under the terms of the GNU General Public License.
Extracted from Wikipedia - GIT Sofware)
What’s the deal with the name? Well, Linus Torvalds has quipped about the name GIT, which is English slang for a stupid or unpleasant person. Torvalds said: I’m an egotistical bastard, and I name all my projects after myself. First ‘Linux’, now ‘GIT’. The man page describes GIT as the stupid content tracker.
Well, basically I want to have a GIT repository in a machine with this address
192.168.0.20 running Linux, with multiple developer machines in this range
192.168.0.30/255 running different operating systems, with access through SSH to the main repository.
- In the server machine (192.168.0.20) create a directory in any place, I’ll name it cixtor.git:
mkdir -p /project/cixtor.git; the .git extension it’s doesn’t matter, this is just a simple directory, but for understanding I will use it as part of the name.
- Then go inside of the folder
- Initialize a GIT repository as Bare
git --bare init. What’s bare?, Bare repositories contain only the .git folder and no working copies of your source files. If you change into a bare repository and display the list of files with
ls -lhas /project/cixtor.gityou’ll find only the GIT folder and nothing else. A bare repository strictly contains the version history of your code.
- Now you can disconnect from the server machine and go to one of the developer machines.
- Now you need to clone the empty repository into the developer machine (from any path of the system) using the SSH credentials of the server machine
git clone fenix @ 192.168.0.20:/project/cixtor.git FenixRepository; supposing that I have an account called fenix registered in the server machine I’ll clone the repository located in /project/cixtor.git into a local folder (not created yet) called FenixRepository; in this point the password of the user of the connection will be prompted (if it’s necessary) and the repository will be created.
Commit & Push
After create the repository we can send a copy of our projects to the server machine and keep an history of changes using GIT, supposing that I don’t want to clone the empty repository but create it from an existent file tree, I’ll go inside the folder with my files and will initialize the GIT repository from this location
cd /home/cixtor/desktop/project/ && git init then I need to associate the remote repository (actually empty) with this local project
git remote add origin [email protected]:/project/cixtor.git and finally I will add all the files in the local project to the HEAD of the local GIT repository
git add ./; now I’ll with send the files to the server using the
commit option of the command
git, it is highly recommended to write a descriptive message explaining the reason why we will send the commit because this message will be very useful when we are checking the history of the project. To send the commit simply use
git commit -m 'This is the first commit of the project' and then
After do this, we will only need to use the command
git add ./ && git commit -m 'Message' && git push to send the changes of our projects to the server, the first part with the
git init and the
git remote ... it isn’t necessary because they are only needed to configure the connection with the remote server. Also they aren’t needed if we are cloning the remote repository because GIT automatically configure the connection with the data supplied with the clone command.
To summarize: the working directory created with
git cloneis my local copy of a project. Its where I add my changes to a project’s code files and test. After I am happy I
git add ./ && git commit -m 'Message'. Then I
git pushto a bare repository, usually on another server, so that other developers can access my changes. When I want to update my local working copy I
git pullto receive the changes that other developers have made.
Jon Saints at What is a bare git repository
Log & Status
When we are working in large projects with many files and many changes, we want generally to separate the changes of one file from others, so we can use
git status to see the differences between the last commit and the current status of the project, and
git log to see the history of commits registered in the local HEAD of the repository, this last command it’s very useful when we want to get back a version of a file or the full project status in some specific date-time.
Graphical User Interface (GUI)
I know that not all of you want to use the command line, and because maybe you’re a Macintosh or Windows user, I will recommend you some GUI tools to control the version history of your project locally. GIT-SCM have a very good list of utilities for each operating system in this webpage GUI Clients, anyway if you are installing GIT from a package manager of compiling from source code you can find GIT-GUI and GITK to committing and browsing the tree version history of your projects.