Logon as “root” on your CentOS 7.2 virtual machine :

[root@git ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

Install “git” :

[root@git ~]# yum -y install git
 git.x86_64 0:

Dependency Installed:
 libgnome-keyring.x86_64 0:3.8.0-3.el7    perl.x86_64 4:5.16.3-286.el7           perl-Carp.noarch 0:1.26-244.el7
 perl-Encode.x86_64 0:2.51-7.el7          perl-Error.noarch 1:0.17020-2.el7      perl-Exporter.noarch 0:5.68-3.el7
 perl-File-Path.noarch 0:2.09-2.el7       perl-File-Temp.noarch 0:0.23.01-3.el7  perl-Filter.x86_64 0:1.49-3.el7
 perl-Getopt-Long.noarch 0:2.40-2.el7     perl-Git.noarch 0:        perl-HTTP-Tiny.noarch 0:0.033-3.el7
 perl-PathTools.x86_64 0:3.40-5.el7       perl-Pod-Escapes.noarch 1:1.04-286.el7 perl-Pod-Perldoc.noarch 0:3.20-4.el7
 perl-Pod-Simple.noarch 1:3.28-4.el7      perl-Pod-Usage.noarch 0:1.63-3.el7     perl-Scalar-List-Utils.x86_64 0:1.27-248.el7
 perl-Socket.x86_64 0:2.010-3.el7         perl-Storable.x86_64 0:2.45-3.el7      perl-TermReadKey.x86_64 0:2.30-20.el7
 perl-Text-ParseWords.noarch 0:3.29-4.el7 perl-Time-HiRes.x86_64 4:1.9725-3.el7  perl-Time-Local.noarch 0:1.2300-2.el7
 perl-constant.noarch 0:1.27-2.el7        perl-libs.x86_64 4:5.16.3-286.el7      perl-macros.x86_64 4:5.16.3-286.el7
 perl-parent.noarch 1:0.225-244.el7       perl-podlators.noarch 0:2.5.1-3.el7    perl-threads.x86_64 0:1.87-4.el7
 perl-threads-shared.x86_64 0:1.43-6.el7  rsync.x86_64 0:3.0.9-17.el7


“git” is now installed :

[root@git ~]# git --version
git version

Configure “git” :

[root@git git]# git config --global user.name "your name"
[root@git git]# git config --global user.email "your email address"
[root@git git]# git config --global core.autocrlf input
[root@git git]# git config --global core.safecrlf true

First example : a new depot

Create your first depot :

[root@git ~]# mkdir /git
[root@git ~]# cd /git
[root@git git]# git init
Initialized empty Git repository in /git/.git/

This command has created files and directories :

[root@git git]# tree -a
└── .git
    ├── branches
    ├── config
    ├── description
    ├── HEAD
    ├── hooks
    │   ├── applypatch-msg.sample
    │   ├── commit-msg.sample
    │   ├── post-update.sample
    │   ├── pre-applypatch.sample
    │   ├── pre-commit.sample
    │   ├── prepare-commit-msg.sample
    │   ├── pre-push.sample
    │   ├── pre-rebase.sample
    │   └── update.sample
    ├── info
    │   └── exclude
    ├── objects
    │   ├── info
    │   └── pack
    └── refs
        ├── heads
        └── tags

Create an example file :

[root@git git]# echo "echo \"here is a stupid script\"" > my_script.sh

Add this file to “git” :

[root@git git]# ls
[root@git git]# git add my_script.sh

What’s the status ?

[root@git git]# git status
# On branch master
# Initial commit
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
# new file: my_script.sh

Commit this addition :

[root@git git]# git commit -m "first file created"
[master (root-commit) 60f3195] first file created
 1 file changed, 1 insertion(+)
 create mode 100644 my_script.sh

See the log :

[root@git git]# git log
commit 60f319524c04a2b01b1cc4f4c41799235e4beb59
Author: your name <your email address>
Date: Thu Dec 31 13:54:54 2015 +0100

first file created

Modify the file :

[root@git git]# echo "echo \"here is a second line\"" >> my_script.sh

What does “git” say ?

[root@git git]# git status
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
# modified: my_script.sh
no changes added to commit (use "git add" and/or "git commit -a")

Display differences since last commit :

[root@git git]# git diff 60f319524c04a2b01b1cc4f4c41799235e4beb59
diff --git a/my_script.sh b/my_script.sh
index 71f8ab8..d1a82b9 100644
--- a/my_script.sh
+++ b/my_script.sh
@@ -1 +1,2 @@
 echo "here is a stupid script"
+echo "here is a second line"

Commit those changes :

[root@git git]# git commit -a -m "a second line added"
[master 2fe046c] a second line added
 1 file changed, 1 insertion(+)

And see the log :

[root@git git]# git log
commit 2fe046cd746a61e2488c0e572f2351862fd57c2e
Author:your name <your email address>
Date: Thu Dec 31 14:11:59 2015 +0100

a second line added

commit 60f319524c04a2b01b1cc4f4c41799235e4beb59
Author:your name <your email address>
Date: Thu Dec 31 13:54:54 2015 +0100

first file created

Second example : cloning an existing depot

Create this directory :

[root@git ~]# mkdir /puppet

[root@git ~]# cd /puppet

Clone from Puppet GitHub :

[root@git puppet]# git clone https://github.com/puppetlabs/puppet
Cloning into 'puppet'...
remote: Counting objects: 200400, done.
remote: Compressing objects: 100% (48/48), done.
remote: Total 200400 (delta 18), reused 0 (delta 0), pack-reused 200352
Receiving objects: 100% (200400/200400), 48.04 MiB | 799.00 KiB/s, done.
Resolving deltas: 100% (145822/145822), done.

Change directory and see the status :

[root@git puppet]# cd puppet
[root@git puppet]# git status
# On branch master
nothing to commit, working directory clean

Display the log for one file, for example :

[root@git puppet]# git log -- acceptance/config/nodes/redhat-7-x86_64.yaml
commit 9e10bab11294c6b23d203d72225ed0ab63fdc1d7
Author: Kylo Ginsberg <kylo@puppetlabs.com>
Date: Sun Mar 22 15:42:52 2015 -0700

    (maint) Cleanup yaml formatting in node configs

    This is no functional change, but for easier diffing with
    yaml files in hiera/facter which were built using ruby's
    yaml library, this touches up the yaml formatting.

    This change was from:

    Dir.glob('./*.yaml') do |f|
      config = YAML.load_file(f)
       File.open(f, 'w') { |f| YAML.dump(config, f) }

commit 4689e08c948615c48bba3850822c3a5478daabed
Author: Michael Smith <michael.smith@puppetlabs.com>
Date: Tue Mar 17 13:34:12 2015 -0700

    (PUP-4195) Clean up config files

    Remove unmaintained config files; i.e. all*, foss*, standalone.
    Update naming to specify the platform and architecture, following a
    format similar to template naming.
    Remove `agent` role from the master, as testing the agent role is
    covered in a specific config.


PDF24 Creator    Send article as PDF   

Leave a Reply

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