How to Install and Use GIT to access GitHub repo for Beginners

      Comments Off on How to Install and Use GIT to access GitHub repo for Beginners

Installing git in Linux machine and How to embedded with Github Account:

==> Git is an excellent version control tool which is most commonly used by most of the companies nowadays.

Install from source code:

$ sudo yum groupinstall "Development Tools"
$ sudo yum install gettext-devel openssl-devel perl-CPAN perl-devel zlib-devel

check the latest version in https://github.com/git/git/releases

$ wget https://github.com/git/git/archive/v2.10.0.tar.gz

$ tar -zxvf v2.10.0.tar.gz

$ cd v2.10.0

$ make configure

$ ./configure –prefix=/usr/local

# make install

# git --version

Install from YUM:

# yum install git

# git --version

For debian:

# apt-get install git

# git --version

How to access your public git repo from local-machine:

==> Login to your github account create a new repo with redmi file [https://github.com/]

==> Summit an username and email, so that the commit messages will be generated with the correct information attached.

$ git config --global user.name "user"
$ git config --global user.email "mailid"

==> See the configuration using,

$ git config --list

==> We need to create an ssh key, for that go to settings -> SSH and GPG keys -> click on New SSH Key
By adding many ssh keys of different developers we can give commit access to them..

==> Create an SSH key in your local machine,

$ ssh-keygen -t rsa -C “mailid”

==> We should enable a ssh-agent to establish the connection with the ssh clients using ssh domain socket,

 $ eval "$(ssh-agent -s)"

==> We need to add the ssh key to the ssh-agent,

$ ssh-add ~/.ssh/id_rsa

==> then copy our public key from /home/user/.ssh/id_rsa.pub and paste it in github SSH and GPG keys new keys location.

==> This ssh key will be shown in green colour once the key is tested, for that we should use the following command,

$ ssh -T [email protected]

==> Our intial setup is finished then we should follow the steps to push and pull our commits

==> create a dirctory in local machine,

$ mkdir test

==> switch into that dirctory

$ cd test

==> give the command to initialize,

$ git init

==> Now you can see one hidden directory onside test and we have that git config files will be present inside
==> Next we need to add the remote github server with this, for that copy the github repo url from clone or download and use with the command

$ git remote add origin https://github.com/yy/zz.git

==> Now we can do the pull operation using,

$ git pull origin master

==> You can do codeing in this test directory during offline and when you think your code is ok then you can do that push operation,

$ touch testfile

$ git add testfile

$ git commit -m “message”
 [master (root-commit) ed691e2] message
 1 file changed, 1 insertion(+)
 create mode 100644 testfile

$ git push -u origin master

==> This will successfully push your commit to the github.

How to delete files from repo:

use, git rm:

$ git rm testfile
$ git commit -m "remove testfile"

If you want to delete only from Git Repository not from your local machine, use the command for delete,

$ git rm --cached testfile

And to push changes to remote repo

$ git push origin branch_name

Troubleshooting:

==> When we git clone, git fetch, git pull, or git push to a remote repository using HTTPS URLs on the command line without ssh-key authentication, we will be asked for your GitHub username and password everytime.

==> If we give it wrong we will get an error
[remote: Anonymous access to yy/zz.git denied.
fatal: Authentication failed for “https://github.com/yy/zz.git“]

To avoid this everytime we should use credential.helper to cache credential to,

$ git config --global credential.helper cache
 [Set git to use the credential memory cache]
$ git config --global credential.helper 'cache --timeout=3600'
 [Set the cache to timeout after 1 hour (setting is in seconds)]

==> If it is asking for username and password of github even after adding ssh key, change the remote repo url to,

$ git remote set-url origin [email protected]:user/repo.git

==> Try now it will work..

Sharing is caring!

About Dinesh Sobitharaj C

An IT professional having multiple years of experience in IT Infrastructure planning, System integrations, Project implementation and delivery. Devops Enthusiast skilled with broad ranges of technology adoption. Well versed with Cloud Computing and Application Service Offerings such as SaaS/PaaS/IaaS. Expert in aligning business goals, mission and process to architect innovative solutions and strategies.