CONTACT @ Skype : rajdimdung   |   call : +977 9841813550

Git and Github ( Version Control)

Post by : SAmal    Date : 2014-12-06 01:18:58

  • Share on Facebook

What is Version Control?

Revision control, also known as version control and source control (and an aspect of software 
configuration management), is the management of changes to documents, computer programs, 
large web sites, and other collections of information.

Quite simply, it is a method used to keep a software system that can consist of many version 
and/or configurations, well organized.

There have been a ton of version control system through the lifetime of software, some are:

- CVS kind of grandfather of source control.
- PVCS commercialized CVS,
- Subversion inspired by CVS 
- Perforce 
- Micro software Visual SourceSafe 
- Mercurial 
- TeamSite 
- Vault
- Bittkkeeper used to manage the Linux kernel before hellip
- Git created by our favorite Linux author and create: Linux! 

Common Sources Tasks:

- Initialization 
  o Creating the empty repository for use 
- Clone 
  o Making a local copy on your workstation 
- Checking Out
  o Locking a copy of one or more files for exclusive use 
- Branching 
  o Allowing a set of files to be developed concurrently and different speeds for different reason. 
- Merging 
  o Taking different branches or set of changes and integrating into one set or branch
- Resolving 
  o Taking conflicting changes from multiple people on the same file and manually addressing 
- Commit 
  o Taking changes from the local system and committing them to the branch. 
- Push/Pull 
  o Taking changes locally or remotely and merging into one or more branches

We’ll be covering GIT from start to finish, including touching on some of the public GIT hosting servides. In addition, we will also cover installing GITLAB, a full web application like Github, that allow you to work with multiple complex.  

 

Installing and Configuration

Installing Git

[root@dlab108 ~]# ls -la
total 40
dr-xr-x---.  4 root root 4096 Oct 29 14:28 .
dr-xr-xr-x. 26 root root 4096 Oct 29 14:24 ..
-rw-------.  1 root root  221 Oct 29 14:29 .bash_history
-rw-r--r--.  1 root root   18 May 20  2009 .bash_logout
-rw-r--r--.  1 root root  176 May 20  2009 .bash_profile
-rw-r--r--.  1 root root  176 Sep 22  2004 .bashrc
-rw-r--r--.  1 root root  100 Sep 22  2004 .cshrc
drwxr-----.  3 root root 4096 Oct 29 14:25 .pki
drwx------.  2 root root 4096 Oct 29 14:24 .ssh
-rw-r--r--.  1 root root  129 Dec  3  2004 .tcshrc
[root@dlab108 ~]#
[root@dlab108 ~]# git config --global user.name "Root User"
[root@dlab108 ~]# git config --global user.email "root@localhost"
[root@dlab108 ~]# ls -la
total 44
dr-xr-x---.  4 root root 4096 Oct 29 14:38 .
dr-xr-xr-x. 26 root root 4096 Oct 29 14:24 ..
-rw-------.  1 root root  221 Oct 29 14:29 .bash_history
-rw-r--r--.  1 root root   18 May 20  2009 .bash_logout
-rw-r--r--.  1 root root  176 May 20  2009 .bash_profile
-rw-r--r--.  1 root root  176 Sep 22  2004 .bashrc
-rw-r--r--.  1 root root  100 Sep 22  2004 .cshrc
-rw-r--r--.  1 root root   49 Oct 29 14:38 .gitconfig
drwxr-----.  3 root root 4096 Oct 29 14:25 .pki
drwx------.  2 root root 4096 Oct 29 14:24 .ssh
-rw-r--r--.  1 root root  129 Dec  3  2004 .tcshrc
[root@dlab108 ~]#

[root@dlab108 ~]# cat .gitconfig
[user]
        name = Root User
        email = root@localhost
[root@dlab108 ~]#

# Or use below command 
[root@dlab108 ~]# git config --list
user.name=Root User
user.email=root@localhost
[root@dlab108 ~]#

Basic Configuration

Now that we�ve installed GIT and completed the basic configuration that allows us to be identified when using it, we are going to take a longer look at the configuration options available to us. We will discuss the difference between system, global and user level options and when you use each one. We�ve three types of configuration: Local, global and system level. 

Verify the Git configuration

[root@dlab108 ~]# git config --list
user.name=Root User
user.email=root@localhost
[root@dlab108 ~]# cat .gitconfig
[user]
        name = Root User
        email = root@localhost
[root@dlab108 ~]#

Create System Level Repo

[root@dlab108 ~]# ls -la /etc/git*
ls: cannot access /etc/git*: No such file or directory
[root@dlab108 ~]# git config --system system.name "Git Repo SErver 1"
[root@dlab108 ~]# ls -la /etc/git*
-rw-r--r--. 1 root root 35 Oct 29 14:57 /etc/gitconfig
 [root@dlab108 ~]# cat /etc/gitconfig
[system]
        name = Get Repo SErver 1
[root@dlab108 ~]#

Configure Global Repo

[root@dlab108 ~]# git config --global system.name "My Git Repo Server1"
[root@dlab108 ~]# git config --list
system.name=Git Repo SErver 1
user.name=Root User
user.email=root@localhost
system.name=My Git Repo Server1

[root@dlab108 ~]# cat .gitconfig
[user]
        name = Root User
        email = root@localhost
[system]
        name = My Git Repo Server1
[root@dlab108 ~]#

Setup 'VIM' as core Editor

[root@dlab108 ~]# git config --global core.editor vim
[root@dlab108 ~]# cat .gitconfig
[user]
        name = Root User
        email = root@localhost
[system]
        name = My Git Repo Server1
[core]
        editor = vim
[root@dlab108 ~]#

Configuure Pager, by default its less so, have added more as well

[root@dlab108 ~]# git config --global core.pager 'more'
[root@dlab108 ~]# cat .gitconfig
[user]
        name = Root User
        email = root@localhost
[system]
        name = My Git Repo Server1
[core]
        editor = vim
        pager = more
[root@dlab108 ~]#

List all the configure you have done for Git Server

[root@dlab108 ~]# git config --list
system.name=Git Repo SErver 1
user.name=Root User
user.email=root@localhost
system.name=My Git Repo Server1
core.editor=vim
core.pager=more
[root@dlab108 ~]#

Create Git ignore Global

[root@dlab108 ~]# vim .gitignore_global
*~
.DB_Store
[root@dlab108 ~]#

[root@dlab108 ~]# git config --global core.excludesfile ~/.gitignore_global
[root@dlab108 ~]# git config --list
system.name=Git Repo SErver 1
user.name=Root User
user.email=root@localhost
system.name=My Git Repo Server1
core.editor=vim
core.pager=more
core.excludesfile=/root/.gitignore_global
[root@dlab108 ~]#

List all the config file, so far what you have done


[root@dlab108 ~]# cat .gitconfig
[user]
        name = Root User
        email = root@localhost
[system]
        name = My Git Repo Server1
[core]
        editor = vim
        pager = more
        excludesfile = /root/.gitignore_global
[root@dlab108 ~]#

Empty Repositories

In this lesson will show the viewer how to create a new empty repository. We will talk about how Git manages our files an revisions while demonstrating some of the basic commands, although exploring the process in detail is handled in subsequent videos. 

Creating our first local repository

// Create Local repository name as �gittest�
 [root@dlab108 ~]# mkdir gittest
[root@dlab108 ~]# cd gittest/
[root@dlab108 gittest]# git init
Initialized empty Git repository in /root/gittest/.git/
[root@dlab108 gittest]# ls -la
total 12
drwxr-xr-x. 3 root root 4096 Oct 31 11:48 .
dr-xr-x---. 5 root root 4096 Oct 31 11:48 ..
drwxr-xr-x. 7 root root 4096 Oct 31 11:48 .git
[root@dlab108 gittest]# cd .git/
 [root@dlab108 .git]# ll
total 32
drwxr-xr-x. 2 root root 4096 Oct 31 11:48 branches
-rw-r--r--. 1 root root   92 Oct 31 11:48 config
-rw-r--r--. 1 root root   73 Oct 31 11:48 description
-rw-r--r--. 1 root root   23 Oct 31 11:48 HEAD
drwxr-xr-x. 2 root root 4096 Oct 31 11:48 hooks
drwxr-xr-x. 2 root root 4096 Oct 31 11:48 info
drwxr-xr-x. 4 root root 4096 Oct 31 11:48 objects
drwxr-xr-x. 4 root root 4096 Oct 31 11:48 refs
[root@dlab108 .git]#
[root@dlab108 .git]# cd objects/
[root@dlab108 objects]# ls -la
total 16
drwxr-xr-x. 4 root root 4096 Oct 31 11:48 .
drwxr-xr-x. 7 root root 4096 Oct 31 11:48 ..
drwxr-xr-x. 2 root root 4096 Oct 31 11:48 info
drwxr-xr-x. 2 root root 4096 Oct 31 11:48 pack
[root@dlab108 objects]# cd .
[root@dlab108 objects]# cd ..
[root@dlab108 .git]# ls
branches  config  description  HEAD  hooks  info  objects  refs
[root@dlab108 .git]# cd ..
[root@dlab108 gittest]# ls
[root@dlab108 gittest]# ls -la
total 12
drwxr-xr-x. 3 root root 4096 Oct 31 11:48 .
dr-xr-x---. 5 root root 4096 Oct 31 11:48 ..
drwxr-xr-x. 7 root root 4096 Oct 31 11:48 .git
[root@dlab108 gittest]#

# Run the below command to check the GIT status 
 [root@dlab108 gittest]# git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)
[root@dlab108 gittest]# 

// Remove the �.git�
[root@dlab108 gittest]# rm -rf .git/
[root@dlab108 gittest]# git status
fatal: Not a git repository (or any of the parent directories): .git
[root@dlab108 gittest]#

// Re-create the �GIT� 
[root@dlab108 gittest]# git init
Initialized empty Git repository in /root/gittest/.git/
[root@dlab108 gittest]# ls -la
total 12
drwxr-xr-x. 3 root root 4096 Oct 31 11:59 .
dr-xr-x---. 5 root root 4096 Oct 31 11:48 ..
drwxr-xr-x. 7 root root 4096 Oct 31 11:59 .git
[root@dlab108 gittest]# git status
# On branch master
#
# Initial commit
#
nothing to commit (create/copy files and use "git add" to track)

//Create Local Content
[root@dlab108 gittest]# echo "This is my first file" > test.txt
[root@dlab108 gittest]# cat test.txt
This is my first file
[root@dlab108 gittest]#

// Still I do not have anything to commit because I did not add into directory 
[root@dlab108 gittest]# git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
#       test.txt
nothing added to commit but untracked files present (use "git add" to track)
[root@dlab108 gittest]#

// Below command add the file into git repo but have not committed yet.  
[root@dlab108 gittest]# git add test.txt
[root@dlab108 gittest]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached ..." to unstage)
#
#       new file:   test.txt
#
[root@dlab108 gittest]#

// Below command will commit the change 

 

 

//  Now the check the GIT status running below command, you will see the nothing to commit because it I�ve already commit using �git commit� 
[root@dlab108 gittest]# git status
# On branch master
nothing to commit (working directory clean)
[root@dlab108 gittest]# ls -la
total 16
drwxr-xr-x. 3 root root 4096 Oct 31 12:18 .
dr-xr-x---. 5 root root 4096 Oct 31 12:26 ..
drwxr-xr-x. 8 root root 4096 Oct 31 12:26 .git
-rw-r--r--. 1 root root   22 Oct 31 12:18 test.txt
[root@dlab108 gittest]# cat test.txt
This is my first file
[root@dlab108 gittest]#

// Lets come out from the directory and let say you have already one directory where you have bunch of file/soure code already and you have to add those file into git repo. In my case I�m creating new dir and file since I do not have that. 

[root@dlab108 gittest]# cd ..
[root@dlab108 ~]# mkdir mydir
[root@dlab108 ~]# cd mydir/
[root@dlab108 mydir]# cp /etc/h* .
cp: omitting directory `/etc/hal'
[root@dlab108 mydir]# ls -la
total 24
drwxr-xr-x. 2 root root 4096 Oct 31 12:29 .
dr-xr-x---. 6 root root 4096 Oct 31 12:29 ..
-rw-r--r--. 1 root root    9 Oct 31 12:29 host.conf
-rw-r--r--. 1 root root  158 Oct 31 12:29 hosts
-rw-r--r--. 1 root root  370 Oct 31 12:29 hosts.allow
-rw-r--r--. 1 root root  460 Oct 31 12:29 hosts.deny
[root@dlab108 mydir]# 

// Ok now I�m in that directory, If I run the �git status� command I�ll get error 
[root@dlab108 mydir]# git status
fatal: Not a git repository (or any of the parent directories): .git
[root@dlab108 mydir]#

// You need to create git repo using below command before you can run the �git status� or any �git� command. 

[root@dlab108 mydir]#  git init
Initialized empty Git repository in /root/mydir/.git/
[root@dlab108 mydir]# 

// Run the below command to run the below command and you will still see the nothing because you have not add to repo and committed it. 
[root@dlab108 mydir]# git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
#       host.conf
#       hosts
#       hosts.allow
#       hosts.deny
nothing added to commit but untracked files present (use "git add" to track)
[root@dlab108 mydir]#

// Run the below command to add and commit the file/source 
[root@dlab108 mydir]# git add *
[root@dlab108 mydir]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached ..." to unstage)
#
#       new file:   host.conf
#       new file:   hosts
#       new file:   hosts.allow
#       new file:   hosts.deny
#
[root@dlab108 mydir]# git commit
[master (root-commit) a062862] This is the initial file commitment for my new repository
 4 files changed, 26 insertions(+), 0 deletions(-)
 create mode 100644 host.conf
 create mode 100644 hosts
 create mode 100644 hosts.allow
 create mode 100644 hosts.deny
[root@dlab108 mydir]#

// Change effect in this way,
// First I ran �git add + � and commit, it says nothing to change 
[root@dlab108 mydir]# git add hosts
[root@dlab108 mydir]# git commit -m hosts
# On branch master
nothing to commit (working directory clean)
[root@dlab108 mydir]# 

// Now I�m editing the file (hosts) and add using �git add hosts� and commit using �git commit hosts� command and I saw the below output as 3 new lines added

[root@dlab108 mydir]# vi hosts
[root@dlab108 mydir]# git add hosts
[root@dlab108 mydir]# git commit -m hosts
[master edb4dad] hosts
 1 files changed, 3 insertions(+), 0 deletions(-)
[root@dlab108 mydir]#

Git Basic

Now that we know how to create and initialize our repositories, we will go back and revisit the commands we used to demonstrate repository management in details. We will cover  the add and commit commands as well as talk about  what 
// List the your home directory file, in my home directory I have zip file called source.tar.gz
[sdimdung@dlab108 ~]$ ls
source.tar.gz
[sdimdung@dlab108 ~]$ 

// create one working directory called source  and cd into it 
[sdimdung@dlab108 ~]$ mkdir source
[sdimdung@dlab108 ~]$ cd source
[sdimdung@dlab108 source]$ 

// Create git repo using �git init� command and run �ls �la�
[sdimdung@dlab108 source]$ git init
Initialized empty Git repository in /home/sdimdung/source/.git/
[sdimdung@dlab108 source]$ ls -al
total 12
drwxrwxr-x. 3 sdimdung sdimdung 4096 Oct 31 15:59 .
drwx------. 3 sdimdung sdimdung 4096 Oct 31 15:59 ..
drwxrwxr-x. 7 sdimdung sdimdung 4096 Oct 31 15:59 .git
[sdimdung@dlab108 source]$ 

// You can see there empty .git repository and run �ls �la� you will see nothing. 
[sdimdung@dlab108 source]$ rm -rf .*
rm: cannot remove directory: `.'
rm: cannot remove directory: `..'
[sdimdung@dlab108 source]$ ls -la
total 8
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:00 .
drwx------. 3 sdimdung sdimdung 4096 Oct 31 15:59 ..
 [sdimdung@dlab108 source]$ 

// When you run the �git status� nothing is there once you delete. 
[sdimdung@dlab108 source]$ git status
fatal: Not a git repository (or any of the parent directories): .git
[sdimdung@dlab108 source]$

// Now Lets untal the source file and take a look what�s in there. 
[sdimdung@dlab108 source]$ tar -zxvf ../source.tar.gz
[sdimdung@dlab108 source]$ ll
total 20
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:13 build
-rw-rw-r--. 1 sdimdung sdimdung    0 Oct 31 16:14 build.xml
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:13 dist
-rw-rw-r--. 1 sdimdung sdimdung    0 Oct 31 16:14 manifest.mf
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:13 nbproject
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:13 src
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:13 test
[sdimdung@dlab108 source]$
[sdimdung@dlab108 source]$ git status
fatal: Not a git repository (or any of the parent directories): .git
[sdimdung@dlab108 source]$ git init
Initialized empty Git repository in /home/sdimdung/source/.git/
[sdimdung@dlab108 source]$ ls -la
total 32
drwxrwxr-x. 8 sdimdung sdimdung 4096 Oct 31 16:18 .
drwx------. 3 sdimdung sdimdung 4096 Oct 31 15:59 ..
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:13 build
-rw-rw-r--. 1 sdimdung sdimdung    0 Oct 31 16:14 build.xml
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:13 dist
drwxrwxr-x. 7 sdimdung sdimdung 4096 Oct 31 16:18 .git
-rw-rw-r--. 1 sdimdung sdimdung    0 Oct 31 16:14 manifest.mf
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:13 nbproject
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:13 src
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:13 test
[sdimdung@dlab108 source]$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
#       build.xml
#       manifest.mf
nothing added to commit but untracked files present (use "git add" to track)
[sdimdung@dlab108 source]$

// 
[sdimdung@dlab108 source]$ git add *
[sdimdung@dlab108 source]$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached ..." to unstage)
#
#       new file:   build.xml
#       new file:   build/build.pp
#       new file:   dist/dd.pp
#       new file:   manifest.mf
#       new file:   nbproject/nb.txt
#       new file:   src/src.txt
#       new file:   test/test.pp
#
[sdimdung@dlab108 source]$
// 
[sdimdung@dlab108 source]$ git commit -m "This is initial source file"
[master (root-commit) 77e44a0] This is initial source file
 Committer: sdimdung 
 5 files changed, 5 insertions(+), 0 deletions(-)
 create mode 100644 build.xml
 create mode 100644 build/build.pp
 create mode 100644 dist/dd.pp
 create mode 100644 manifest.mf
 create mode 100644 nbproject/nb.txt
 create mode 100644 src/src.txt
 create mode 100644 test/test.pp
[sdimdung@dlab108 source]$

// 
[sdimdung@dlab108 source]$ git status
# On branch master
nothing to commit (working directory clean)
[sdimdung@dlab108 source]$ rm manifest.mf
[sdimdung@dlab108 source]$ ls
build  build.xml  dist  nbproject  src  test
[sdimdung@dlab108 source]$ git status
# On branch master
# Changed but not updated:
#   (use "git add/rm ..." to update what will be committed)
#   (use "git checkout -- ..." to discard changes in working directory)
#
#       deleted:    manifest.mf
#
no changes added to commit (use "git add" and/or "git commit -a")
[sdimdung@dlab108 source]$ git rm manifest.mf
rm 'manifest.mf'
[sdimdung@dlab108 source]$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD ..." to unstage)
#
#       deleted:    manifest.mf
#
[sdimdung@dlab108 source]$
[sdimdung@dlab108 source]$ git commit -m "Test delation of a file"
[master eafcfef] Test delation of a file
 Committer: sdimdung 
 0 files changed, 0 insertions(+), 0 deletions(-)
 delete mode 100644 manifest.mf
[sdimdung@dlab108 source]$

Git Ignore

we will revisit the glogal Git Ignore file created in an earlier video to demonstrate the difference in granularity between a system level option and a repository option overriding it in the .gitignore file. 

// Create directory called �gitignore�
[sdimdung@dlab108 ~]$ mkdir gitignore
[sdimdung@dlab108 ~]$ cd gitignore/
[sdimdung@dlab108 gitignore]$

// Tar source.tar.gz file to gitignore directory 
[sdimdung@dlab108 gitignore]$ tar -xzvf ../source.tar.gz
[sdimdung@dlab108 gitignore]$

// List the file on gitignore directory 
[sdimdung@dlab108 gitignore]$ ll
total 28
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:34 build
-rw-rw-r--. 1 sdimdung sdimdung   27 Nov  1 00:52 build.xml
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:34 dist
-rw-rw-r--. 1 sdimdung sdimdung   25 Nov  1 00:56 manifest.mf
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:35 nbproject
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:35 src
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:36 test
[sdimdung@dlab108 gitignore]$


// Create empty git repository 
 [sdimdung@dlab108 gitignore]$ git init
Initialized empty Git repository in /home/sdimdung/gitignore/.git/
[sdimdung@dlab108 gitignore]$

// Check git status 
[sdimdung@dlab108 gitignore]$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
#       build.xml
#       build/
#       dist/
#       manifest.mf
#       nbproject/
#       src/
#       test/
nothing added to commit but untracked files present (use "git add" to track)
[sdimdung@dlab108 gitignore]$

[sdimdung@dlab108 ~]$ sudo su -
[root@dlab108 ~]# clear
[root@dlab108 ~]# cat .gitignore_global
*~
.DB_Store
[root@dlab108 ~]# exit
logout
[sdimdung@dlab108 ~]$ cd gitignore/
[sdimdung@dlab108 gitignore]$ vim .gitignore
[sdimdung@dlab108 gitignore]$ cat .gitignore
*.mf
[sdimdung@dlab108 gitignore]$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
#       .gitignore
#       build.xml
#       build/
#       dist/
#       nbproject/
#       src/
#       test/
nothing added to commit but untracked files present (use "git add" to track)
[sdimdung@dlab108 gitignore]$ git add *
The following paths are ignored by one of your .gitignore files:
manifest.mf
Use -f if you really want to add them.
fatal: no files added
[sdimdung@dlab108 gitignore]$

[sdimdung@dlab108 gitignore]$ ll
total 28
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:34 build
-rw-rw-r--. 1 sdimdung sdimdung   27 Nov  1 00:52 build.xml
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:34 dist
-rw-rw-r--. 1 sdimdung sdimdung   25 Nov  1 00:56 manifest.mf
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:35 nbproject
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:35 src
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:36 test
[sdimdung@dlab108 gitignore]$ git add build
[sdimdung@dlab108 gitignore]$ git add build.xml
[sdimdung@dlab108 gitignore]$ git add dist/
[sdimdung@dlab108 gitignore]$ git add nbproject
[sdimdung@dlab108 gitignore]$ git add src
[sdimdung@dlab108 gitignore]$ git add test
[sdimdung@dlab108 gitignore]$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached ..." to unstage)
#
#       new file:   build.xml
#       new file:   build/build.pp
#       new file:   dist/dd.pp
#       new file:   nbproject/nb.txt
#       new file:   src/src.txt
#       new file:   test/test.pp
#
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
#       .gitignore
[sdimdung@dlab108 gitignore]$

[sdimdung@dlab108 gitignore]$ git commit -m "Version 0.0.0."
[master (root-commit) 09e6629] Version 0.0.0.
 Committer: sdimdung 
 6 files changed, 6 insertions(+), 0 deletions(-)
 create mode 100644 build.xml
 create mode 100644 build/build.pp
 create mode 100644 dist/dd.pp
 create mode 100644 nbproject/nb.txt
 create mode 100644 src/src.txt
 create mode 100644 test/test.pp
[sdimdung@dlab108 gitignore]$

[sdimdung@dlab108 gitignore]$ vim .gitignore
[sdimdung@dlab108 gitignore]$ git status
# On branch master
nothing to commit (working directory clean)
[sdimdung@dlab108 gitignore]$

Cloning

Cloning : Local Repositories

we will discuss two of the three methods of cloning a repository using local file system tool as well as git. We will also talk about how to push and pupp our changes from our clones back to the original repository and begin discussing branches (particularly �origin master�).
 

//Cloning Local Repositories 
[sdimdung@dlab108 ~]$ ls
gitignore  source  source.tar.gz
[sdimdung@dlab108 ~]$ cd gitignore/
[sdimdung@dlab108 gitignore]$ git status
# On branch master
nothing to commit (working directory clean)
[sdimdung@dlab108 gitignore]$ cd

// Clone Local Repositories �gitigngore� to �repo2� and run the �git status� it should working as like it working on �gitignore�. 
[sdimdung@dlab108 ~]$ cp -rf gitignore/ repo2
[sdimdung@dlab108 ~]$ cd repo2/
[sdimdung@dlab108 repo2]$ git status
# On branch master
nothing to commit (working directory clean)
[sdimdung@dlab108 repo2]$
[sdimdung@dlab108 repo2]$ ll
total 28
drwxrwxr-x. 2 sdimdung sdimdung 4096 Nov  1 17:29 build
-rw-rw-r--. 1 sdimdung sdimdung   27 Nov  1 17:29 build.xml
drwxrwxr-x. 2 sdimdung sdimdung 4096 Nov  1 17:29 dist
-rw-rw-r--. 1 sdimdung sdimdung   25 Nov  1 17:29 manifest.mf
drwxrwxr-x. 2 sdimdung sdimdung 4096 Nov  1 17:29 nbproject
drwxrwxr-x. 2 sdimdung sdimdung 4096 Nov  1 17:29 src
drwxrwxr-x. 2 sdimdung sdimdung 4096 Nov  1 17:29 test
[sdimdung@dlab108 repo2]$

Note: This the way of above is not correct, this only copy those original and disconnect forever and there is no way to  like back again . 

// Lets clone the Local Repository in proper way 
[sdimdung@dlab108 ~]$ rm -rf repo2/
[sdimdung@dlab108 ~]$ mkdir repos
[sdimdung@dlab108 ~]$ cd repos/
[sdimdung@dlab108 repos]$ git clone /home/sdimdung/gitignore/ testignore
Initialized empty Git repository in /home/sdimdung/repos/testignore/.git/
[sdimdung@dlab108 repos]$
[sdimdung@dlab108 repos]$ ls
testignore
[sdimdung@dlab108 repos]$ cd testignore/
 [sdimdung@dlab108 testignore]$ ll
total 24
drwxrwxr-x. 2 sdimdung sdimdung 4096 Nov  1 17:37 build
-rw-rw-r--. 1 sdimdung sdimdung   27 Nov  1 17:37 build.xml
drwxrwxr-x. 2 sdimdung sdimdung 4096 Nov  1 17:37 dist
drwxrwxr-x. 2 sdimdung sdimdung 4096 Nov  1 17:37 nbproject
drwxrwxr-x. 2 sdimdung sdimdung 4096 Nov  1 17:37 src
drwxrwxr-x. 2 sdimdung sdimdung 4096 Nov  1 17:37 test
[sdimdung@dlab108 testignore]$
[sdimdung@dlab108 testignore]$ echo "this is a file edit " > testfile.text
[sdimdung@dlab108 testignore]$ ls -la
total 36
drwxr-xr-x. 7 sdimdung sdimdung 4096 Nov  1 17:43 .
drwxrwxr-x. 3 sdimdung sdimdung 4096 Nov  1 17:37 ..
drwxrwxr-x. 2 sdimdung sdimdung 4096 Nov  1 17:37 build
-rw-rw-r--. 1 sdimdung sdimdung   27 Nov  1 17:37 build.xml
drwxrwxr-x. 2 sdimdung sdimdung 4096 Nov  1 17:37 dist
drwxrwxr-x. 8 sdimdung sdimdung 4096 Nov  1 17:37 .git
drwxrwxr-x. 2 sdimdung sdimdung 4096 Nov  1 17:37 nbproject
drwxrwxr-x. 2 sdimdung sdimdung 4096 Nov  1 17:37 src
-rw-rw-r--. 1 sdimdung sdimdung   21 Nov  1 17:41 testfile.text
[sdimdung@dlab108 testignore]$
[sdimdung@dlab108 testignore]$ git status
# On branch master
# Changed but not updated:
#   (use "git add/rm ..." to update what will be committed)
#   (use "git checkout -- ..." to discard changes in working directory)
#
#       deleted:    test/test.pp
#
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
#       testfile.text
no changes added to commit (use "git add" and/or "git commit -a")
[sdimdung@dlab108 testignore]$

[sdimdung@dlab108 testignore]$ git add testfile.text
[sdimdung@dlab108 testignore]$ git commit -m "testfile.txt"
[master 17136c9] testfile.txt
 Committer: sdimdung 

 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 testfile.text
[sdimdung@dlab108 testignore]$

[sdimdung@dlab108 testignore]$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
#
nothing to commit (working directory clean)
[sdimdung@dlab108 testignore]$

[sdimdung@dlab108 testignore]$ git push
Counting objects: 6, done.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 469 bytes, done.
Total 5 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (5/5), done.
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable t
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing int
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in som
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, se
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To /home/sdimdung/gitignore/
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '/home/sdimdung/gitignore/'
[sdimdung@dlab108 testignore]$

// Now need to go back to the original directory where we�ve cloned from , to do so please follow the below steps 

[sdimdung@dlab108 testignore]$ cd
[sdimdung@dlab108 ~]$ cd gitignore/
[sdimdung@dlab108 gitignore]$ ll
total 28
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:34 build
-rw-rw-r--. 1 sdimdung sdimdung   27 Nov  1 00:52 build.xml
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:34 dist
-rw-rw-r--. 1 sdimdung sdimdung   25 Nov  1 00:56 manifest.mf
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:35 nbproject
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:35 src
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:36 test
[sdimdung@dlab108 gitignore]$ git pull ../repos/testignore/
From ../repos/testignore
 * branch            HEAD       -> FETCH_HEAD
Updating 09e6629..ebe938a
Fast-forward
 test/test.pp  |    1 -
 testfile.text |    1 +
 2 files changed, 1 insertions(+), 1 deletions(-)
 delete mode 100644 test/test.pp
 create mode 100644 testfile.text
[sdimdung@dlab108 gitignore]$ ll
total 28
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:34 build
-rw-rw-r--. 1 sdimdung sdimdung   27 Nov  1 00:52 build.xml
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:34 dist
-rw-rw-r--. 1 sdimdung sdimdung   25 Nov  1 00:56 manifest.mf
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:35 nbproject
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:35 src
-rw-rw-r--. 1 sdimdung sdimdung   21 Nov  1 19:07 testfile.text
[sdimdung@dlab108 gitignore]$

 [sdimdung@dlab108 gitignore]$ cd ../repos/testignore/
[sdimdung@dlab108 testignore]$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
#
nothing to commit (working directory clean)
[sdimdung@dlab108 testignore]$
[sdimdung@dlab108 testignore]$ git push
Everything up-to-date
[sdimdung@dlab108 testignore]$ git status
# On branch master
nothing to commit (working directory clean)
[sdimdung@dlab108 testignore]$

Cloning: Remote Repositoris

we will discuss two of the three methods of cloning a repository using remote system tool as well as git. We will also talk about how to push and pull our changes from our clones back to the original repository and begin discussing branches (particularly �origin master�). 


[sdimdung@dlab108 ~]$ ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 06:27:46:66:7E:E9
          inet addr:10.108.0.134  Bcast:10.108.0.255  Mask:255.255.255.0
          inet6 addr: fe80::427:46ff:fe66:7ee9/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:65656 errors:0 dropped:0 overruns:0 frame:0
          TX packets:49477 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:40031604 (38.1 MiB)  TX bytes:10215575 (9.7 MiB)
          Interrupt:247
[sdimdung@dlab108 ~]$ 
[sdimdung@dlab108 ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/sdimdung/.ssh/id_rsa):
Created directory '/home/sdimdung/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/sdimdung/.ssh/id_rsa.
Your public key has been saved in /home/sdimdung/.ssh/id_rsa.pub.
The key fingerprint is:
e7:7b:01:b2:cc:b3:06:f7:99:d3:5a:4d:0a:d2:2b:82 sdimdung@dlab108
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|                 |
|        ...      |
|       oSo+.  .  |
|     .. *+ o.+   |
|    E .o.+o+o..  |
|       .o.=oo    |
|       .  o+     |
+-----------------+
[sdimdung@dlab108 ~]$

[sdimdung@dlab108 ~]$ ssh-copy-id sdimdung@10.108.0.134
sdimdung@10.108.0.134's password:
Now try logging into the machine, with "ssh 'sdimdung@10.108.0.134'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

[sdimdung@dlab108 ~]$

// Clone the repot from remote server to local using ssh 

[sdimdung@gitlocal ~]$ git clone sdimdung@54.183.215.114:/home/sdimdung/gitignore localrepo
Initialized empty Git repository in /home/sdimdung/localrepo/.git/
remote: Counting objects: 18, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 18 (delta 2), reused 0 (delta 0)
Receiving objects: 100% (18/18), 1.14 KiB, done.
Resolving deltas: 100% (2/2), done.
 [sdimdung@gitlocal ~]$ ll
total 4
drwxr-xr-x. 7 sdimdung sdimdung 4096 Nov  1 19:55 localrepo
[sdimdung@gitlocal ~]$ cd localrepo/
[sdimdung@gitlocal localrepo]$ ll
total 24
drwxrwxr-x. 2 sdimdung sdimdung 4096 Nov  1 19:55 build
-rw-rw-r--. 1 sdimdung sdimdung   27 Nov  1 19:55 build.xml
drwxrwxr-x. 2 sdimdung sdimdung 4096 Nov  1 19:55 dist
drwxrwxr-x. 2 sdimdung sdimdung 4096 Nov  1 19:55 nbproject
drwxrwxr-x. 2 sdimdung sdimdung 4096 Nov  1 19:55 src
-rw-rw-r--. 1 sdimdung sdimdung   21 Nov  1 19:55 testfile.text
[sdimdung@gitlocal localrepo]$ git status
# On branch master
nothing to commit (working directory clean)
[sdimdung@gitlocal localrepo]$
[sdimdung@gitlocal localrepo]$ echo "This is testfile2.txt from Local repot to r                                                                                                              emote repo" > testfie2.txt
[sdimdung@gitlocal localrepo]$ ll
total 28
drwxrwxr-x. 2 sdimdung sdimdung 4096 Nov  1 19:55 build
-rw-rw-r--. 1 sdimdung sdimdung   27 Nov  1 19:55 build.xml
drwxrwxr-x. 2 sdimdung sdimdung 4096 Nov  1 19:55 dist
drwxrwxr-x. 2 sdimdung sdimdung 4096 Nov  1 19:55 nbproject
drwxrwxr-x. 2 sdimdung sdimdung 4096 Nov  1 19:55 src
-rw-rw-r--. 1 sdimdung sdimdung   54 Nov  1 19:59 testfie2.txt
-rw-rw-r--. 1 sdimdung sdimdung   21 Nov  1 19:55 testfile.text
[sdimdung@gitlocal localrepo]$ git status
# On branch master
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
#       testfie2.txt
nothing added to commit but untracked files present (use "git add" to track)
[sdimdung@gitlocal localrepo]$ git add *
[sdimdung@gitlocal localrepo]$ git commit -m "Commit From Local Repot to Remote"
[master 5bbfcfc] Commit From Local Repot to Remote
 Committer: sdimdung 

 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 testfie2.txt
[sdimdung@gitlocal localrepo]$

[sdimdung@gitlocal localrepo]$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)
[sdimdung@gitlocal localrepo]$

Tagging, Branching and Merging

Tags

This video will introduce the viewer to the concept of tagging and how it differs from branches. We will talk about the immutability of a tag and when you would use it vs. a branch (or in conjunction with one).

[sdimdung@dlab108 ~]$ ll
total 16
drwxrwxr-x. 7 sdimdung sdimdung 4096 Nov  1 20:03 gitignore
drwxr-xr-x. 7 sdimdung sdimdung 4096 Nov  1 19:39 localrepo
drwxrwxr-x. 3 sdimdung sdimdung 4096 Nov  1 17:37 repos
-rw-rw-r--. 1 sdimdung sdimdung  484 Nov  1 01:01 source.tar.gz
[sdimdung@dlab108 ~]$ cd gitignore/
[sdimdung@dlab108 gitignore]$ ll
total 32
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:34 build
-rw-rw-r--. 1 sdimdung sdimdung   27 Nov  1 00:52 build.xml
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:34 dist
-rw-rw-r--. 1 sdimdung sdimdung   25 Nov  1 00:56 manifest.mf
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:35 nbproject
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:35 src
-rw-rw-r--. 1 sdimdung sdimdung   24 Nov  1 20:03 test1.text
-rw-rw-r--. 1 sdimdung sdimdung   21 Nov  1 19:07 testfile.text
[sdimdung@dlab108 gitignore]$
[sdimdung@dlab108 gitignore]$ git status
# On branch master
nothing to commit (working directory clean)
[sdimdung@dlab108 gitignore]$

/// Crating Tag called �tag1� and add t
[sdimdung@dlab108 gitignore]$ git tag tag1
[sdimdung@dlab108 gitignore]$ git tag
tag1
[sdimdung@dlab108 gitignore]$ echo "tag1 post" > posttag.txt
[sdimdung@dlab108 gitignore]$ git status
# On branch master
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
#       posttag.txt
nothing added to commit but untracked files present (use "git add" to track)
 [sdimdung@dlab108 gitignore]$ git add posttag.txt
 [sdimdung@dlab108 gitignore]$ git commit -m  "Post Tag1 commit"
[master 1a07bb1] Post Tag1 commit
 Committer: sdimdung 

 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 posttag.txt
[sdimdung@dlab108 gitignore]$ git status
# On branch master
nothing to commit (working directory clean)
[sdimdung@dlab108 gitignore]$

// List the Tags using below command 
[sdimdung@dlab108 gitignore]$ git show tag1
commit 5d04ab45f8dfc10cf9375a1ce1999c866ee016d2
Author: sdimdung 
Date:   Sat Nov 1 20:20:45 2014 -0400

    x

diff --git a/manifest.mf b/manifest.mf
new file mode 100644
index 0000000..6d100e5
--- /dev/null
+++ b/manifest.mf
@@ -0,0 +1 @@
+This is manifest.mf file
diff --git a/test1.text b/test1.text
new file mode 100644
index 0000000..b99ac8f
--- /dev/null
+++ b/test1.text
@@ -0,0 +1 @@
+This is new update for
[sdimdung@dlab108 gitignore]$ 

// Describe the tags using below commands 
[sdimdung@dlab108 gitignore]$ git describe --tags
tag1-1-g1a07bb1
[sdimdung@dlab108 gitignore]$ 

Note: Above able explain tag1 = tags name , 1 = number of committed and gla07bb1= commitd reference. 

[sdimdung@dlab108 gitignore]$ ll
total 36
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:34 build
-rw-rw-r--. 1 sdimdung sdimdung   27 Nov  1 00:52 build.xml
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:34 dist
-rw-rw-r--. 1 sdimdung sdimdung   25 Nov  1 00:56 manifest.mf
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:35 nbproject
-rw-rw-r--. 1 sdimdung sdimdung   10 Nov  1 20:26 posttag.txt
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:35 src
-rw-rw-r--. 1 sdimdung sdimdung   24 Nov  1 20:03 test1.text
-rw-rw-r--. 1 sdimdung sdimdung   21 Nov  1 19:07 testfile.text
[sdimdung@dlab108 gitignore]$

Branches

We will introduce the concept of branching your source/revision repository and the difference between branching and tagging and why and where you would branch as opposed to tagging. 

// Run the command to see the status of git on gitignore repo
[sdimdung@dlab108 gitignore]$ git status
# On branch master
nothing to commit (working directory clean)
[sdimdung@dlab108 gitignore]$

// Make sure you don�t have any branches before you create new one 
[sdimdung@dlab108 gitignore]$ git branch -a
* master
[sdimdung@dlab108 gitignore]$ 



// Create new Branch called �development�
[sdimdung@dlab108 gitignore]$git checkout -b development
Switched to a new branch 'development'
[sdimdung@dlab108 gitignore]$

// Now if you run the �git stattus� you will see you are in the development branch 
[sdimdung@dlab108 gitignore]$ git status
# On branch development
nothing to commit (working directory clean)
[sdimdung@dlab108 gitignore]$

// Now we can see the two branches and current branches is donated with * (asterisk) 
[sdimdung@dlab108 gitignore]$ git branch -a
* development
  master
[sdimdung@dlab108 gitignore]$

//  Try creating branch which already exit 
[sdimdung@dlab108 gitignore]$ git branch -a
* development
  master
[sdimdung@dlab108 gitignore]$ git checkout -b development
fatal: git checkout: branch development already exists
[sdimdung@dlab108 gitignore]$

// Lets switch back to the Master branches, you are currently in development branches 
[sdimdung@dlab108 gitignore]$ git branch -a
* development
  master
[sdimdung@dlab108 gitignore]$
[sdimdung@dlab108 gitignore]$ ll
total 36
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:34 build
-rw-rw-r--. 1 sdimdung sdimdung   27 Nov  1 00:52 build.xml
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:34 dist
-rw-rw-r--. 1 sdimdung sdimdung   25 Nov  1 00:56 manifest.mf
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:35 nbproject
-rw-rw-r--. 1 sdimdung sdimdung   10 Nov  1 20:26 posttag.txt
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:35 src
 [sdimdung@dlab108 gitignore]$ git checkout master
Switched to branch 'master'
[sdimdung@dlab108 gitignore]$ git status
# On branch master
nothing to commit (working directory clean)
[sdimdung@dlab108 gitignore]$ git branch -a
  development
* master
[sdimdung@dlab108 gitignore]$
// Add some file 
[sdimdung@dlab108 gitignore]$ echo "THIS IS MASTER ONLY" >  MASTERBRANCH.TXT
[sdimdung@dlab108 gitignore]$ git status
# On branch master
# Changed but not updated:
#   (use "git add/rm ..." to update what will be committed)
#   (use "git checkout -- ..." to discard changes in working directory)
#
#       deleted:    test1.text
#
# Untracked files:
#   (use "git add ..." to include in what will be committed)
#
#       MASTERBRANCH.TXT
no changes added to commit (use "git add" and/or "git commit -a")
[sdimdung@dlab108 gitignore]$ git add MASTERBRANCH.TXT
[sdimdung@dlab108 gitignore]$ git commit MASTERBRANCH.TXT
[master b32d4c0] Master branch commit
 Committer: sdimdung 

 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 MASTERBRANCH.TXT
[sdimdung@dlab108 gitignore]$

[sdimdung@dlab108 gitignore]$ git status
# On branch master
nothing to commit (working directory clean)
[sdimdung@dlab108 gitignore]$

// Lets switch to the development branch 
[sdimdung@dlab108 gitignore]$ git status
# On branch master
nothing to commit (working directory clean)
[sdimdung@dlab108 gitignore]$ git checkout development
Switched to branch 'development'
[sdimdung@dlab108 gitignore]$ git status
# On branch development
nothing to commit (working directory clean)
[sdimdung@dlab108 gitignore]$

// Now if you list the directory you won�t see the MASTERBRANCH.TXT because we created for only master branch, once you create development branch, and if anything change to master branch, it will not change to the development or any other branch. 
[sdimdung@dlab108 gitignore]$  ll
total 36
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:34 build
-rw-rw-r--. 1 sdimdung sdimdung   27 Nov  1 00:52 build.xml
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:34 dist
-rw-rw-r--. 1 sdimdung sdimdung   25 Nov  1 00:56 manifest.mf
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:35 nbproject
-rw-rw-r--. 1 sdimdung sdimdung   10 Nov  1 20:26 posttag.txt
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:35 src
-rw-rw-r--. 1 sdimdung sdimdung   24 Nov  1 22:02 test1.text
-rw-rw-r--. 1 sdimdung sdimdung   21 Nov  1 19:07 testfile.text
[sdimdung@dlab108 gitignore]$

// Now Create some file in Development branch 
[sdimdung@dlab108 gitignore]$ echo "Development Branch" > DEVEL.TXT
[sdimdung@dlab108 gitignore]$ git add DEVEL.TXT
[sdimdung@dlab108 gitignore]$ git commit -m "DEVL"
[development 8fe5828] DEVL
 Committer: sdimdung 

 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 DEVEL.TXT
[sdimdung@dlab108 gitignore]$

// Now you can see the DEVEL.TXT file already created on development branch 
[sdimdung@dlab108 gitignore]$ git status
# On branch development
nothing to commit (working directory clean)
[sdimdung@dlab108 gitignore]$ ll
total 40
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:34 build
-rw-rw-r--. 1 sdimdung sdimdung   27 Nov  1 00:52 build.xml
-rw-rw-r--. 1 sdimdung sdimdung   19 Nov  1 22:09 DEVEL.TXT
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:34 dist
-rw-rw-r--. 1 sdimdung sdimdung   25 Nov  1 00:56 manifest.mf
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:35 nbproject
-rw-rw-r--. 1 sdimdung sdimdung   10 Nov  1 20:26 posttag.txt
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:35 src
-rw-rw-r--. 1 sdimdung sdimdung   24 Nov  1 22:02 test1.text
-rw-rw-r--. 1 sdimdung sdimdung   21 Nov  1 19:07 testfile.text
[sdimdung@dlab108 gitignore]$

// Now switch back to the maser branche and verify whether the devl.txt file present or not
[sdimdung@dlab108 gitignore]$ git checkout master
Already on 'master'
[sdimdung@dlab108 gitignore]$ ll
total 36
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:34 build
-rw-rw-r--. 1 sdimdung sdimdung   27 Nov  1 00:52 build.xml
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:34 dist
-rw-rw-r--. 1 sdimdung sdimdung   25 Nov  1 00:56 manifest.mf
-rw-rw-r--. 1 sdimdung sdimdung   20 Nov  1 22:16 MASTERBRANCH.TXT
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:35 nbproject
-rw-rw-r--. 1 sdimdung sdimdung   10 Nov  1 20:26 posttag.txt
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:35 src
-rw-rw-r--. 1 sdimdung sdimdung   21 Nov  1 19:07 testfile.text
[sdimdung@dlab108 gitignore]$

Merging

Merging:  now that we have tagged and /or branched our revisions, we will learn how to marge them inline into an existing branch to now reflect the changes of the branched copy up to the point of merging. 

// Now Verify the in what  branch you are in
[sdimdung@dlab108 gitignore]$ git status
# On branch master
nothing to commit (working directory clean)
[sdimdung@dlab108 gitignore]$

// Verify how many branch you have in using below command. 
[sdimdung@dlab108 gitignore]$git branch -a
  development
* master
[sdimdung@dlab108 gitignore]$

// Below you can see the content of MASTERBRANCH.TXT 
[sdimdung@dlab108 gitignore]$ ls -la
total 48
drwxrwxr-x. 7 sdimdung sdimdung 4096 Nov  1 22:23 .
drwx------. 6 sdimdung sdimdung 4096 Nov  1 22:14 ..
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:34 build
-rw-rw-r--. 1 sdimdung sdimdung   27 Nov  1 00:52 build.xml
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:34 dist
drwxrwxr-x. 8 sdimdung sdimdung 4096 Nov  1 22:23 .git
-rw-rw-r--. 1 sdimdung sdimdung   25 Nov  1 00:56 manifest.mf
-rw-rw-r--. 1 sdimdung sdimdung   20 Nov  1 22:23 MASTERBRANCH.TXT
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:35 nbproject
-rw-rw-r--. 1 sdimdung sdimdung   10 Nov  1 20:26 posttag.txt
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:35 src
-rw-rw-r--. 1 sdimdung sdimdung   21 Nov  1 19:07 testfile.text
[sdimdung@dlab108 gitignore]$

// Now switch to the Development Branch using below command and verify the content 
[sdimdung@dlab108 gitignore]$ git checkout development
Switched to branch 'development'
[sdimdung@dlab108 gitignore]$ ll
total 40
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:34 build
-rw-rw-r--. 1 sdimdung sdimdung   27 Nov  1 00:52 build.xml
-rw-rw-r--. 1 sdimdung sdimdung   19 Nov  1 23:02 DEVEL.TXT
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:34 dist
-rw-rw-r--. 1 sdimdung sdimdung   25 Nov  1 00:56 manifest.mf
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:35 nbproject
-rw-rw-r--. 1 sdimdung sdimdung   10 Nov  1 20:26 posttag.txt
drwxrwxr-x. 2 sdimdung sdimdung 4096 Oct 31 16:35 src
-rw-rw-r--. 1 sdimdung sdimdung   24 Nov  1 23:02 test1.text
-rw-rw-r--. 1 sdimdung sdimdung   21 Nov  1 19:07 testfile.text
[sdimdung@dlab108 gitignore]$

// Merging multiple branches to production branch (master)
// Verify the current branch
[sdimdung@dlab108 gitignore]$ git branch -a
* development
  Master
[sdimdung@dlab108 gitignore]$

// Switch back to the master/production branch 
[sdimdung@dlab108 gitignore]$ git checkout master
Switched to branch 'master'
[sdimdung@dlab108 gitignore]$

//Check the status, nothing to add/commit
[sdimdung@dlab108 gitignore]$ git status
# On branch master
nothing to commit (working directory clean)
[sdimdung@dlab108 gitignore]$




// Now marge the development to the production 
[sdimdung@dlab108 gitignore]$ git merge development --no-ff
Merge made by recursive.
 DEVEL.TXT |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 DEVEL.TXT
[sdimdung@dlab108 gitignore]$ git status
# On branch master
nothing to commit (working directory clean)
[sdimdung@dlab108 gitignore]$

// List the file/content whether its exist or not 
[sdimdung@dlab108 gitignore]$ ls
build      DEVEL.TXT  manifest.mf       nbproject    src
build.xml  dist       MASTERBRANCH.TXT  posttag.txt  testfile.text
[sdimdung@dlab108 gitignore]$
// After mergin the branch you still have both branch (development and master/production)
[sdimdung@dlab108 gitignore]$ git branch -a
  development
* master
[sdimdung@dlab108 gitignore]$

Logging and Reposiotry Auditing

Git Log

This lesson will go into details about the build in logging facility contained with GIT. We will give multiple examples about how to view the history of our repository of our repository by commit, by date, byt user or by branche as well as show how to view it in multiple ways (including a nifty graphing format to visually identify branches and merges). 

// Viewing GIT logs
[sdimdung@dlab108 gitignore]$ git log | less 

// you can run below command to view the number of commit at last 
[sdimdung@dlab108 gitignore]$ git log -p -2
commit 28de95bd09b5ef9a38a2137af5f10c8f4e59d99e
Merge: 3680928 8fe5828
Author: Samal Dimdung 
Date:   Sat Nov 1 23:13:32 2014 -0400

    Merge branch 'development'

commit 8fe5828bd706851b756ed7bac3cad6300030926c
Author: sdimdung 
Date:   Sat Nov 1 22:11:44 2014 -0400

    DEVL

diff --git a/DEVEL.TXT b/DEVEL.TXT
new file mode 100644
index 0000000..a2f245f
--- /dev/null
+++ b/DEVEL.TXT
@@ -0,0 +1 @@
+Development Branch
[sdimdung@dlab108 gitignore]$

[sdimdung@dlab108 gitignore]$ git status
# On branch master
nothing to commit (working directory clean)
[sdimdung@dlab108 gitignore]$

// Log command �git log �stat�
[sdimdung@dlab108 gitignore]$ git log --stat
commit 28de95bd09b5ef9a38a2137af5f10c8f4e59d99e
Merge: 3680928 8fe5828
Author: Samal Dimdung 
Date:   Sat Nov 1 23:13:32 2014 -0400

    Merge branch 'development'

commit 8fe5828bd706851b756ed7bac3cad6300030926c
Author: sdimdung 
Date:   Sat Nov 1 22:11:44 2014 -0400

    DEVL

 DEVEL.TXT |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

commit 3680928de00265736b13b9c98130d1b49c826ee7
Author: sdimdung 
Date:   Sat Nov 1 22:01:44 2014 -0400

    delted test.txt

 test1.text |    1 -
[sdimdung@dlab108 gitignore]$

// Log command � git log �pretty=oneline�
[sdimdung@dlab108 gitignore]$ git log --pretty=oneline
28de95bd09b5ef9a38a2137af5f10c8f4e59d99e Merge branch 'development'
8fe5828bd706851b756ed7bac3cad6300030926c DEVL
3680928de00265736b13b9c98130d1b49c826ee7 delted test.txt
b32d4c03f6fd65b608863d9d2a89828ef7b84274 Master branch commit
1a07bb150cb53a3b09ed83aa82b856d9f94d148d Post Tag1 commit
5d04ab45f8dfc10cf9375a1ce1999c866ee016d2 x
ebe938a3084d80f7391d85ef1fd9a9d9f536d0e6 testdir deleted
17136c96bea9dfa94c773b1bd0539bfc96b7203a testfile.txt
09e6629f03fa4d0a57ce5a60e3216dfe7cb94c79 Version 0.0.0.
[sdimdung@dlab108 gitignore]$

// use git log --pretty=format:"%h:, %an, %ae, %cn, %cd, -%s"
[sdimdung@dlab108 gitignore]$ git log --pretty=format:"%h:, %an, %ae, %cn, %cd, -%s"
28de95b:, Samal Dimdung, dimdung@gmail.com, Samal Dimdung, Sat Nov 1 23:13:32 2014 -0400, -Merge branch 'development'
8fe5828:, sdimdung, sdimdung@dlab108.(none), sdimdung, Sat Nov 1 22:11:44 2014 -0400, -DEVL
3680928:, sdimdung, sdimdung@dlab108.(none), sdimdung, Sat Nov 1 22:01:44 2014 -0400, -delted test.txt
b32d4c0:, sdimdung, sdimdung@dlab108.(none), sdimdung, Sat Nov 1 22:00:10 2014 -0400, -Master branch commit
1a07bb1:, sdimdung, sdimdung@dlab108.(none), sdimdung, Sat Nov 1 20:28:00 2014 -0400, -Post Tag1 commit
5d04ab4:, sdimdung, sdimdung@dlab108.(none), sdimdung, Sat Nov 1 20:20:45 2014 -0400, -x
ebe938a:, sdimdung, sdimdung@dlab108.(none), sdimdung, Sat Nov 1 17:46:56 2014 -0400, -testdir deleted
17136c9:, sdimdung, sdimdung@dlab108.(none), sdimdung, Sat Nov 1 17:44:58 2014 -0400, -testfile.txt
09e6629:, sdimdung, sdimdung@dlab108.(none), sdimdung, Sat Nov 1 01:20:21 2014 -0400, -Version 0.0.0.
[sdimdung@dlab108 gitignore]$

// Using �git log --pretty=format:"%h: %an, %ae, %cn, %cd, - %s" �graph�
[sdimdung@dlab108 gitignore]$ git log --pretty=format:"%h: %an, %ae, %cn, %cd, - %s" --graph
*   28de95b: Samal Dimdung, dimdung@gmail.com, Samal Dimdung, Sat Nov 1 23:13:32 2014 -0400, - Merge branch 'development'
|\
| * 8fe5828: sdimdung, sdimdung@dlab108.(none), sdimdung, Sat Nov 1 22:11:44 2014 -0400, - DEVL
* | 3680928: sdimdung, sdimdung@dlab108.(none), sdimdung, Sat Nov 1 22:01:44 2014 -0400, - delted test.txt
* | b32d4c0: sdimdung, sdimdung@dlab108.(none), sdimdung, Sat Nov 1 22:00:10 2014 -0400, - Master branch commit
|/
* 1a07bb1: sdimdung, sdimdung@dlab108.(none), sdimdung, Sat Nov 1 20:28:00 2014 -0400, - Post Tag1 commit
* 5d04ab4: sdimdung, sdimdung@dlab108.(none), sdimdung, Sat Nov 1 20:20:45 2014 -0400, - x
* ebe938a: sdimdung, sdimdung@dlab108.(none), sdimdung, Sat Nov 1 17:46:56 2014 -0400, - testdir deleted
* 17136c9: sdimdung, sdimdung@dlab108.(none), sdimdung, Sat Nov 1 17:44:58 2014 -0400, - testfile.txt
* 09e6629: sdimdung, sdimdung@dlab108.(none), sdimdung, Sat Nov 1 01:20:21 2014 -0400, - Version 0.0.0.
[sdimdung@dlab108 gitignore]$

Related Posts