1.Install Git
[root@centos123 ~]#yum install git (command to run on the linux/unix terminal)
Loaded plugins: rhnplugin, security
This system is receiving updates from RHN Classic or RHN Satellite.
Setting up Install Process
epel/metalink                                                                                                                         |  10 kB     00:00
epel                                                                                                                                  | 4.3 kB     00:00
epel/primary_db                                                                                                                       | 5.8 MB     00:04
Resolving Dependencies
–> Running transaction check
—> Package git.x86_64 0:1.7.1-3.el6_4.1 will be installed
–> Processing Dependency: perl-Git = 1.7.1-3.el6_4.1 for package: git-1.7.1-3.el6_4.1.x86_64

git                               x86_64                        1.7.1-3.el6_4.1                           rhel6-x86_64-2015-07                        4.6 M
Installing for dependencies:
perl-Error                        noarch                        1:0.17015-4.el6                           rhel6-x86_64-2015-07                         29 k
perl-Git                          noarch                        1.7.1-3.el6_4.1                           rhel6-x86_64-2015-07                         28 kTransaction Summary
Install       3 Package(s)Total download size: 4.7 M
Installed size: 0
Is this ok [y/N]: y
Downloading Packages:
(1/3): git-1.7.1-3.el6_4.1.x86_64.rpm                                                                                                 | 4.6 MB     00:00
(2/3): perl-Error-0.17015-4.el6.noarch.rpm                                                                                            |  29 kB     00:00
(3/3): perl-Git-1.7.1-3.el6_4.1.noarch.rpm                                                                                            |  28 kB     00:00
Total                                                                                                                        3.5 MB/s | 4.7 MB     00:01
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
Installing : 1:perl-Error-0.17015-4.el6.noarch                                                                                                         1/3
Installing : perl-Git-1.7.1-3.el6_4.1.noarch                                                                                                           2/3
Installing : git-1.7.1-3.el6_4.1.x86_64                                                                                                                3/3
Verifying  : git-1.7.1-3.el6_4.1.x86_64                                                                                                                1/3
Verifying  : perl-Git-1.7.1-3.el6_4.1.noarch                                                                                                           2/3
Verifying  : 1:perl-Error-0.17015-4.el6.noarch                                                                                                         3/3Installed:
git.x86_64 0:1.7.1-3.el6_4.1

  1. I have created a sample dir (gitexample) and changed to it and Initialzed git
    Following are commands
    [root@\kumar ~]# mkdir gitexample
    [root@\kumar ~]# ls -ltr
    total 8
    drwxr-xr-x 2 root root 4096 Jan 28 06:00 Downloads
    drwxr-xr-x 2 root root 4096 Jan 28 06:53 gitexample
    [root@\kumar ~]# cd gitexample
    [root@\kumar gitexample]#
    [root@\kumar gitexample]# git init     ( this command initializes the git under gitexample directory).
    Initialized empty Git repository in /root/gitexample/.git/
    [root@\kumar gitexample]#
  2. Status of the repository
    [root@\kumar gitexample]# git status
    # On branch master
    # Initial commit
    nothing to commit (create/copy files and use “git add” to track)
    [root@\kumar gitexample]#
  3. Adding your content to repository
    I have created a file ( under gitexmple directory. Now after creating the file , when I run the git status , we get the following out put.
    [root@\kumar gitexample]# git status
    # On branch master
    # Initial commit
    # Untracked files:
    #   (use “git add <file>…” to include in what will be committed)
    nothing added to commit but untracked files present (use “git add” to track)
    [root@\kumar gitexample]#
  4. Adding the file to staging area
    [root@\kumar gitexample]# git add
    Adding it to staging area , would track the changes made to the file.
    Verifying it
    [root@\kumar gitexample]# git status
    # On branch master
    # Initial commit
    # Changes to be committed:
    #   (use “git rm –cached <file>…” to unstage)
    #       new file:
    [root@\kumar gitexample]#
    Now the file is in the satging area but not in repository yet.
    To Move it to repo , run commit command
  5. Moving the code file from staging area to Repository.
    [root@\kumar gitexample]# git commit -m “adding version 1 of to repo”
    [master (root-commit) c3f96f5] adding version 1 of to repo
    Committer: root <root@kumar>
    1 files changed, 2 insertions(+), 0 deletions(-)
    create mode 100755
    [root@\kumar gitexample]#
  6. In the below example I have created 3 files with file as part of there name.
    [root@\kumar gitexample]# touch samplefile1 samplefile2 filesample1
    [root@\kumar gitexample]# ls -ltr
    total 4
    -rwxr-xr-x 1 root root 41 Jan 28 07:06
    -rw-r–r– 1 root root  0 Jan 28 07:22 samplefile2
    -rw-r–r– 1 root root  0 Jan 28 07:22 samplefile1
    -rw-r–r– 1 root root  0 Jan 28 07:22 filesample1
    Adding all the content to staging area
    [root@\kumar gitexample]# git add *file*
    [root@\kumar gitexample]# git status
    # On branch master
    # Changes to be committed:
    #   (use “git reset HEAD <file>…” to unstage)
    #       new file:   filesample1
    #       new file:   samplefile1
    #       new file:   samplefile2
    [root@\kumar gitexample]#
  7. Adding all the content to repo.
    [root@\kumar gitexample]# git commit -m “all files adding to repo”
    [master af1d3a8] all files adding to repo
    Committer: root <root@kumar>
    0 files changed, 0 insertions(+), 0 deletions(-)
    create mode 100644 filesample1
    create mode 100644 samplefile1
    create mode 100644 samplefile2
    [root@\kumar gitexample]#
  8. Now create a new empty github repository.
  9. Now push our local repo to the GitHub server , for this you need to add a remote repository.
    git remote add origin github url (command)This command takes a remote name and a repository URL, which in your case is
    Go ahead and run git remote add with the options below:git remote add origin
    1.list available branches
    [root@centos123 ~]# git branch
    * master
    2. command to create a new branch
    [root@centos123 ~]# git branch example1_branch
    [root@centos123 ~]# git branch
    example1_branch – new branch created.
    * master

2 Replies to “GIT”

Leave a Reply

Your email address will not be published. Required fields are marked *