Git (Hub)

On this guide we will lay grounds on configuring and using Git on our machine.

  • Installing Git agent on our machine.
  • Creating a git project on Github.
  • Generating public/private rsa key pair.
  • Adding a new SSH key to your GitHub account.
  • Testing your SSH connection.
  • Cloning a project from Github to our machine.
  • Committing changes toGithub.

Installing git agent on our machine

$ sudo yum install git
$ git --version
git version 1.9.1

Creating a git project on Github

  1. Go to https://github.com/ .
  2. Sign in (or sign up if you don’t have a use already).
  3. Click the green New Repository button, and follow the instructions.

Generating public/private rsa key pair.

Following https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/

$ ssh-keygen -t rsa -b 4096 -C "segyair@gmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/yairs/.ssh/id_rsa): /home/yairs/.ssh/github
Enter passphrase (empty for no passphrase): 
Your identification has been saved in /home/yairs/.ssh/github.
Your public key has been saved in /home/yairs/.ssh/github.pub.
The key fingerprint is:
<fingerprint> segyair@gmail.com
The key's randomart image is:
<randomart image>
$ ll /home/yairs/.ssh/
drwx------ 2 yairs yairs 4.0K Oct 31 11:52 ./
drwxr-xr-x 76 yairs yairs 4.0K Oct 31 11:50 ../
-rw------- 1 yairs yairs 3.3K Oct 31 11:52 github
-rw-r--r-- 1 yairs yairs 743 Oct 31 11:52 github.pub
-rw------- 1 yairs yairs 52K Aug 23 16:39 known_hosts

Adding a new SSH key to your GitHub account

Following https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/

Add (copy to clipboard and paste) the public generated key (github.pub) to a New SSH Key (here: https://github.com/settings/ssh)

Testing your SSH connection

Following https://help.github.com/articles/testing-your-ssh-connection/

$ ssh -i .ssh/github -T git@github.com
Warning: Permanently added the RSA host key for IP address '192.30.253.113' to the list of known hosts.
Hi segyair! You've successfully authenticated, but GitHub does not provide shell access.

TIP: To avoid supplying the path to our private key each time ssh to Github, let’s create a ~/.ssh/config file, and configure our private key there:

$ cat ~/.ssh/config 
Host github.com
 HostName github.com
 User git
 IdentityFile /home/yairs/.ssh/github
 IdentitiesOnly yes
 StrictHostKeyChecking no
$ ssh -T git@github.com
Hi segyair! You've successfully authenticated, but GitHub does not provide shell access.

Cloning a project from Github to our machine

$ git clone git@github.com:segyair/hello-world.git
Cloning into 'hello-world'...
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 5 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (5/5), done.
Checking connectivity... done.
$ cd hello-world/
$ ll
total 24K
drwxr-xr-x 3 yairs yairs 4.0K Oct 31 13:53 ./
drwxr-xr-x 3 yairs yairs 4.0K Oct 31 13:53 ../
drwxr-xr-x 8 yairs yairs 4.0K Oct 31 13:53 .git/
-rw-r--r-- 1 yairs yairs 1.1K Oct 31 13:53 .gitignore
-rw-r--r-- 1 yairs yairs 1.1K Oct 31 13:53 LICENSE
-rw-r--r-- 1 yairs yairs 13   Oct 31 13:53 README.md

And there is our project!

Committing changes to gitub

Let’s modify the README.md file, and commit it to Github

$ vim README.md 
$ git st
## master...origin/master
 M README.md
$ git commit -am"testing git push"
[master c77b5f9] testing git push
 1 file changed, 3 insertions(+), 1 deletion(-)
$ git push
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 292 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local objects.
To git@github.com:segyair/hello-world.git
 76ffc55..c77b5f9 master -> master

And we can see our changed on github:

github_commit

Global Git configurations

Including some handy shortcuts and configurations – https://git-scm.com/docs/git-config

For example:

$ ~/.gitconfig:
[user]
  name = Yair Segal
  email = segyair@gmail.com
[alias]
 co = checkout
 br = branch
 hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
 st = status --short -b
 df = diff -w --color-words
 lg = "log --graph --pretty=format:'%Cred%h%Creset %C(blue)%cn%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative"
Advertisements
This entry was posted in Centos and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

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