Saturday, May 2, 2015

Creating a Repository and committing the changes

In git you would need to initialize a Repository first which would be empty at the start point.

We are going to create a test directory and initialize the directory as our git Repository

~ $ mkdir test
~ $ cd test/
~/test $ git init
Initialized empty Git repository in /root/test/.git/

Initializing a directory creates a subdirectory of .git which includes files used by git to track the changes

~/test $ cd .git/
~/test/.git $ ll
total 32
drwxr-xr-x. 2 root root 4096 May  1 20:11 branches
-rw-r--r--. 1 root root   92 May  1 20:11 config
-rw-r--r--. 1 root root   73 May  1 20:11 description
-rw-r--r--. 1 root root   23 May  1 20:11 HEAD
drwxr-xr-x. 2 root root 4096 May  1 20:11 hooks
drwxr-xr-x. 2 root root 4096 May  1 20:11 info
drwxr-xr-x. 4 root root 4096 May  1 20:11 objects
drwxr-xr-x. 4 root root 4096 May  1 20:11 refs

If we are going to check in the test directory , the git will show there is nothing to commit

~/test $ git status
# On branch master
# Initial commit
nothing to commit (create/copy files and use "git add" to track)

So we are going to create an test.txt file
~/test $ echo "This is just my test file" > test.txt

Now if we are going to check the git status , it will treat this as untracked since its not been added to git yet

~/test $ git status
# On branch master
# Initial commit
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#       test.txt
nothing added to commit but untracked files present (use "git add" to track)

Git Installation and Basic configuration

You can simply install git using the yum

# yum install git

It will resolve the dependencies for you mostly comprising of the perl which git actually uses and will install the git.

Next configure a global username and email id

~ $ git config --global user.name "Root User"
~ $ git config --global user.email "root@localhost"

This would actually create an .gitconfig file which will hold your details

~ $ ls -ltr .gitconfig
-rw-r--r--. 1 root root 49 May  1 17:35 .gitconfig
~ $ pwd

~ $ cat .gitconfig
        name = Root User
        email = root@localhost

You may also list the details using the following command

~ $ git config --list
user.name=Root User

Git is designed to take the parameters locally and globally , so you may set additional parameters and can even set the same parameters to have different value both locally and globally

$ git config --system system.name "Git Repo Server 1"
$ git config --list
system.name=Git Repo Server 1
user.name=Root User

$ git config --global system.name "My Git Repo Server1"
$ git config --list
system.name=Git Repo Server 1
user.name=Root User
system.name=My Git Repo Server1

You can also set the editor in the git that you are going to use

~ $ git config --global core.editor vim
~ $ cat .gitconfig
        name = Root User
        email = root@localhost
        name = My Git Repo Server1
        editor = vim

It is also possible to define the page option in git whether it would be less or more. By default its less if nothing is specified you may use more

~ $ git config --global core.pager 'more'
~ $ git config --list
system.name=Git Repo Server 1
user.name=Root User
system.name=My Git Repo Server1

Common Source Tasks in Git

Creating the Empty repository for use. Repository are much like the Linux Repos which contain all the source or version control files and directories. So it is necessary to initialize a Empty Repository where you can important all the stuffs and files into.

Making a local full copy of a repository on your workstation. Where you can further work and create further branch or manipulate or add the functionality as per your requirement.

Checking out:
Locking a copy of one or more files for exclusive use. Though it is not mostly used , it was essentially used in the visualsource or perforce, it was done to make sure no one else can make changes which may either conflict or overwrite your changes. Checking out not commonly done today and there are other better way to achieve it.

Allowing a set of files to be developed concurrently and at different speeds for different reasons.It allows to attain different functionality.

Taking different Branches or set of changes and integrating into one set of branch.

Taking Conflicting changes from the multiple people on the same files and manually addressing those conflicts to achieve the Merging.

Taking the Changes from the local system and commiting them to the Branch. You are going to clone the branch and will work on it and after the changes are done you need to commit the changes to merge them to the Branch you were working on.

Taking changes locally or remotedly and merging them into one or more branches.

Understanding Version Control and Available Version Control Softwares

What is Version control
It is a method used to keep a software system that can consist of many versions and configurations , well organized.

Why Version control
Usually through a period of the software development we might have various versions of software, code updates, hot fixes, bug fixes which all are revised over a period of time but we need to maintain the version and keep all the version intact so we might refrence them back over a period of time. Also in case of a problem with an updaded version of a software , we can always revert back to the older version easily using the version control software. All these things can easily be achieved using th version control software.

There are large number of version control softwares
1. CVS: Kind of origin of source control
2. PVCS: Commercialized CVS
3. Subversion: inspired by CVS
4. Perforce: It is a commercial, proprietary revision control system developed by Perforce Software, Inc.
5. Microsoft visual sourcesafe:- Microsoft solution but its not updated since 2005.
6. Mercurial:- Another famous version control and open source, (hg symbol) is quite often used.
7. Teamsite: microsoft solution for version control
8. Vault: usually marketted as a replacement for the Microsoft's Visual Source Safe.
9. Bitkeeper:- used to manage the Linux kernel before Linus Torvalds created Git.
10. Git:- Created by our favourite Linux Author and creator. Linus Torvalds