Technical: Installing and Using GIT Command Line Interface on CentOS

Technical: Installing and Using GIT Command Line Interface on CentOS

Background

Now that my primary box is this CentOS Linux box, I need to make sure that I can share a bit on it.

With a web browser, I am able to post to wordpress.

And, I probably can look for a web interface to get to github, as well.  But, I really need to re-familiarize with Bash and command line stuff.

And, so I will stay away from nice, pretty GUI for now.  And, go shell.

 

Installation

On CentOS, we can install via the yum.

sudo yum install git-core

Yum install is easy as it takes care of installing all the dependant files.

 

Customize

 

Set User name

git config --global user.name "Daniel Adeniji"

Set email address


git config --global user.email "Daniel_Adeniji@nobody.com"

 

 

Create a repository

Connect to your github online account, and create a new repository

 

Identify local folder on host

On your Linux\Cent OS host, identify or create local folder that will serve as your working folder.

In our case, we will use /home/dadeniji/development/apache.org/tomcat/MSAdventureWorksDWDB.Public

 

Change Working Directory

Make identified folder your working directory

Launch Unix terminal and change working folder to identified folder.

Syntax:

cd <working-folder>

 

Sample

cd /home/dadeniji/development/apache.org/tomcat/MSAdventureWorksDWDB.Public

 

Clone Git Repository

Clone Git Repository

Syntax:

git clone git@github.com:<user-name>/<file>.git

 

Sample:


git clone git@github.com:DanielAdeniji/JavaJSPJSTLMSSQL.git

 

Output:

Here is the output we got back…




[dadeniji@adelia MSAdventureWorksDWDB.Public]$ ssh -vT git@github.com
OpenSSH_6.6, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [192.30.252.130] port 22.
debug1: Connection established.
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /home/dadeniji/.ssh/known_hosts:2

debug1: No more authentication methods to try.
Permission denied (publickey).
[dadeniji@adelia MSAdventureWorksDWDB.Public]$ 


 

 

Set up SSH Keys

We know that we have yet to set up SSH keys on this box.  And, unfortunately I do not recollect where I placed previously used ones.

So let us go re-create SSH (Private & Public) keys.

Thankfully, GitHub has very good documentation on doing so:
https://help.github.com/articles/generating-ssh-keys

SSH Key Folder Location

SSH Keys are kept in /home/<username>/.ssh and in our case it is /home/dadeniji/.ssh.

In Linux by convention folders whose name starts with . are hidden files.  And, so the folder might not show up.

Here is a default listing Folder Listing:

Folder-List-Visually

 

Enhanced Folder Listing:

On CentOS, to view hidden files, please click on the menu items “View”/ “Show Hidden Views” or use the keystrokes (CTRL-H).

Here is the “Show Hidden Views” picture:

Folder-List-Visually-after

 

 

Check for SSH Key

Command:


cd ~/.ssh
ls -al

Output:

 

ssh - list files

Generate SSH Key

Command:

ssh-keygen -t rsa -C "dadeniji@ephraimtech.com"

 

Output:

ssh-keygen

 

Add Key to SSH Agent

Command:

ssh-add ~/.ssh/id_rsa

 

Output:

ssh-add

 

Review SSH Keys

Let us re-issue ls, and see whether we now have our keys.

Command:

cd ~/.ssh
ls -al

Output:

ssh - list files (found)

Add SSH Keys to Git-Hub

  • Access Github
  • In the top bar (https://github.com)
  • topMenuClick on the wrench button    wrench  .
  • The “Account Settings” ( https://github.com/settings/profile ) will show up
  • The “Account Settings” screen looks like this:AccountSettings
  • Click on “SSH Keys”
  • SSH Keys:Listing for SSH Keys.SSHKeys
  • Click on the “Add SSH key”AddSSHKey
  • Post entering SSH KeyAddSSHKey [after]
  • Confirm password to continue — Enter passwordConfirmPasswordToContinue
  • Here is the the listing of our “SSH Keys”SSHKeys (After)
    We can see that the new key’s status is listed as  “Added just now — Never used“.

SSH Key – Test

Command:

ssh -T git@github.com

 

Output:

Output – Textual:


[dadeniji@adelia ~]$ ssh -T git@github.com
Warning: Permanently added the RSA host key for IP address '192.30.252.129' to the list of known hosts.
Hi DanielAdeniji! You've successfully authenticated, but GitHub does not provide shell access.
[dadeniji@adelia ~]$


Output – Image:

PermanentlyAddedTheRSAHostKeyForIPAddress

 

 

Clone Git Repository (Attempt #2)

Clone Git Repository

Syntax:

cd <home-directory>

git clone git@github.com:<user-name>/<file>.git

 

Sample:


cd /home/dadeniji/development/apache.org/tomcat/MSAdventureWorksDWDB.Public git clone git@github.com:DanielAdeniji/JavaJSPJSTLMSSQL.git

 

Output:

Here is the output we got back…

Textual:


Initialized empty Git repository in /home/dadeniji/development/apache.org/tomcat/MSAdventureWorksDWDB.Public/JavaJSPJSTLMSSQL/.git/
warning: You appear to have cloned an empty repository.


 

Image:

cloned-empty-git-repository

 

Git Repository – Add

Add Files

Syntax:

cd <home-directory>

git add <files>

 

Sample:


git add '*.jsp'

 

Output:

Textual:

fatal: Not a git repository (or any of the parent directories): .git

 

Image:

NotAGitRepository

 

Remediate

Googling on the error message tells me that I really needed to have indicated the folder that I wanted to use as my Git current folder.

As we did not indicate otherwise, a new folder is created underneath the current folder bearing:

inproper-use-of-git-clone

 

In the screen above the name of the folder is JavaJSPJSTLMSSQL.

 

Move Git Local Repository

Move Git Local Repository

Syntax:

cd <home-directory>

mv <local-folder>/.git . 

rm -rf <local-folder>

 

Sample:


cd /home/dadeniji/development/apache.org/tomcat/MSAdventureWorksDWDB.Public move JavaJSPJSTLMSSQL/.git . rm -rf JavaJSPJSTLMSSQL

 

Check Git Local Repository

 

Syntax:

git status --short

 

Sample:


git status --short

 

Output:

gitStatus--short

 

Reset Git Local Repository – Reset

 

Syntax:

git reset --hard

 

Sample:


git reset --hard

 

Output:

Textual:


fatal: Failed to resolve 'HEAD' as a valid ref.

 

Image:

failed to resolve head

 

We will ignore this error for now.

Git Repository – Add

Add Files

Syntax:

cd <home-directory>

git add <files>

 

Sample:


git add 'README.md'
git add '*.jsp'
git add '*.html'
git add 'META-INF/context.xml'
git add 'WEB-INF/*'

Git Repository – Create ignore file (.gitignore)

Add Files

Syntax:

touch .gitignore

 

Sample:

 

touch .gitignore

 

If there are files that we do not want shipped-off, we will list them in the .gitignore file.

Mask Private Data

We will like to share source code, but keep certain private data hidden.  We will use sed for that.

 

Sample:


sed --expression='s/HRPROD/dbHost/' --expression='s/username="hrdb"/username="dbUser"/' --expression='s/mygoodpwd/dbUserPassword/' META-INF/context.xml > META-INF/context.xml.tmp && mv META-INF/context.xml.tmp META-INF/context.xml sed --expression='s/HRPROD/dbHost/' --expression='s/hrdb;/dbUser;/' --expression='s/mygoodpwd/dbUserPassword/' jspSimple.jsp > jspSimple.jsp.tmp && mv jspSimple.jsp.tmp jspSimple.jsp

 

 

 

Git – Review File Status

Review Git Status in terms of what files are on.

Syntax:

git status

 

Sample:

git status

 

Output:

gitStatus

 

 

Git – Commit Changes – Locally

Commit Git Changes locally.

Syntax:

git commit -m <comment>

 

Sample:

git commit -a -m "initial batch"

 

Output:

gitCommit

 

Git – Commit Changes – Remotely

Commit Git Changes remotely.

Syntax:

git push -u origin master

Sample:

git push -u origin master

 

Output:

gitPush

 

Git – Review Github

Let us quickly review Github and make sure that our files are there.

Our URL is https://github.com/DanielAdeniji/JavaJSPJSTLMSSQL.

 

exploreFilesOnGithub

 

 

 

Git – Review Log

We use “git log” to review our change logs.

Syntax:

git log

Sample:

git log

Output:

gitLog

 

Listening to

Dave Loggins – Pieces of April
https://www.youtube.com/watch?v=gAlaYEmS0oY

 

 

References

References – Git – Tutorial

 

References – Git – SSH Key Management

 

References – Git – Q/A

 

References – Git – SSH Key – QA

 

 

References – SSH Key – Management

  • Git Tutorial starting with git using 10 commands

 

 

 

 

 

 

 

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s