Skip to main content

What is GIT and GITHUB?, How to use GIT and GITHUB?

  SCM(Source code management) is a very important area for all the developers who are working in team. If multiple developer are writing code for an application then it is very important to manage that code properly for fast delivery. There are lots of tools available in market like Mercurial SCM, Apache Subversion, Fossil, Git & GitHub.
  You can think like code can be shared using emails, shared drives or somehow using file share techniques as well, then why SCM is required? Yes, you are correct if we just want to share code then these medium you can use. These are easy mediums but query comes that how you will track the code?, how you will check who has written and what has written? for this we need a code tracking technique and this kind of code tracking is known as versioning(version control). So finally we can say that using SCM we can share the code between multiple developers and also track the code and maintain versioning of it.
  There are two types of SCM we have - CSCM(Centralized Source Code Management) and DSCM(Decentralized Source Code Management). In CSCM we need networking so if any how networking is not there then you can't share your code and if someone has updated any code it won't be visible to another developer. Where DSCM doesn't required any external network connectivity. If both the developers are in same network then it is quite enough.
Note:- Please don't compare both of them, both are good but depends upon use case.
  Here I'll share how to use Git & GitHub. So let's setup lab environment on windows and Linux both and move for practical experience.
Windows:-

  • Download GIT from Git website
  • Just double click and install Git same as you install other windows s/w. If you need help please have a look on a youtube video

Linux :-

  • Make sure yum/dnf is configured
RHEL/Centos version 7 or below
[root@server109 ~]# yum install git -y
RHEL/Centos version 8
[root@server109 ~]# yum install git -y
Ubuntu or any debian package 
[root@server109 ~]# apt-get install git -y
I am launching Git bash terminal and starting practical on windows, exactly same command work fine in Linux as well.
Priyanshi@Priyanshi-PC MINGW64 ~
$ pwd
/c/Users/Priyanshi
$ cd d:
$ mkdir mygit1
$ cd My/Msi\ Laptop/Training/DevOpsAL/mygit/
$ ls
mygit1/  mytest.py
$ pwd
/d/My/Msi Laptop/Training/DevOpsAL/myws
$ git status
fatal: not a git repository (or any of the parent directories): .git
Mean of this command is that my current directory is unknown for git. So to make it known for Git use below and this process is knows as making a repository.
$ git init
Initialized empty Git repository in D:/My/Msi Laptop/Training/DevOpsAL/myws/.git/
Priyanshi@Priyanshi-PC MINGW64 /d/My/Msi Laptop/Training/DevOpsAL/myws (master)
$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
$ cat >> web.html
This is my home page
$ git status
On branch master
No commits yet
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        web.html
nothing added to commit but untracked files present (use "git add" to track)
Priyanshi@Priyanshi-PC MINGW64 /d/My/Msi Laptop/Training/DevOpsAL/myws (master)
$ git status -s
?? web.html
$ git add web.html
$ git status -s
A  web.html
Tell you identity to git that where you would like to share the code. I am giving the same email Id using I created my git account. You have to do this only once.
$ git config --global user.email "kumar.rakesh05@outlook.com"
$ git config --global user.name "Rakesh Kumar"
$ git config --global --list
user.email=kumar.rakesh05@outlook.com
user.name=Rakesh Kumar
Now git know who are you and where do you want to commit, so you can commit,
$ git commit -m "This is my first commit" web.html
[master (root-commit) f8bdbb6] This is my first commit
 1 file changed, 1 insertion(+)
 create mode 100644 web.html
git log command help us to check all the versions, Author(who committed), version number and version etc.
$ git log web.html
commit 706f86dd627547876ad64c3aa69ed9780d064d52 (HEAD -> master)
Author: Rakesh Kumar <kumar.rakesh05@outlook.com>
Date:   Thu Apr 30 13:41:25 2020 +0530
     Few more changes Commit
commit 743e53980a86b28a9dab4523f7fc15da9c05319b
Author: Rakesh Kumar <kumar.rakesh05@outlook.com>
Date:   Thu Apr 30 13:41:02 2020 +0530
    2nd Commit
commit 6c97e7a2ca185b98214340b50a3b7de8775e87b9
Author: Rakesh Kumar <kumar.rakesh05@outlook.com>
Date:   Thu Apr 30 13:40:39 2020 +0530
    2nd Commit
commit f8bdbb6e3a282104730d46e6fe8c3c560a38fbaa
Author: Rakesh Kumar <kumar.rakesh05@outlook.com>
Date:   Thu Apr 30 13:36:58 2020 +0530
    This is my first commit
$ git push - Command is used to upload data to repository a destination of your data. But before that you have to tell git that where, on which URL or we can say we have to give our destination name. How to tell? using $ git remote command. let's do
Once we have set our remote system now we have to set a link between local and remote system. For this we use command syntax like "git push --set-upstream myname_or_anyname master"
$ git remote add myname_or_anyname https://github.com/jay2tinku/devopsal2.git
$ git remote -v
myname_or_anyname       https://github.com/jay2tinku/devopsal2.git (fetch)
myname_or_anyname       https://github.com/jay2tinku/devopsal2.git (push)
$ git push --set-upstream myname_or_anyname master
Enumerating objects: 15, done.
Counting objects: 100% (15/15), done.
Delta compression using up to 4 threads
Compressing objects: 100% (9/9), done.
Writing objects: 100% (15/15), 1.20 KiB | 175.00 KiB/s, done.
Total 15 (delta 3), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (3/3), done.
To https://github.com/jay2tinku/devopsal2.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'myname_or_anyname'.
$ git add new.html - To add a file to git so that git can track this file changes.
[root@server106 html]# git log
commit a44404e6399b3f94755637fabf881c3010f8d15e (HEAD -> master, origin/master, origin/HEAD)
Author: Rakesh Kumar <kumar.rakesh05@outlook.com>
Date:   Thu Apr 30 14:30:09 2020 +0530
    I missed bg color again
commit 21506b4f838f8ee9a15adb0e71293abc9fe0bcf6
Author: Rakesh Kumar <kumar.rakesh05@outlook.com>
Date:   Thu Apr 30 14:26:41 2020 +0530
    I missed bg color
commit c8669fbd0a100c3127a35fdf98e5a2458d26153b
Author: Rakesh Kumar <kumar.rakesh05@outlook.com>
Date:   Thu Apr 30 14:23:15 2020 +0530
    page set with color
commit fcf2057c8d5e8d4b593d0c46593f21e970682666
Author: Rakesh Kumar <kumar.rakesh05@outlook.com>
Date:   Thu Apr 30 14:08:56 2020 +0530
    Firt commit of this file
commit 278d3d7a92a6fc8ad33e32adc7f550a139f4ebb4
Author: Rakesh Kumar <kumar.rakesh05@outlook.com>
Date:   Thu Apr 30 13:45:28 2020 +0530
    changes using cat
commit 706f86dd627547876ad64c3aa69ed9780d064d52
Author: Rakesh Kumar <kumar.rakesh05@outlook.com>
[root@server106 html]#
Here my web server is using "commit a44404e6399b3f94755637fabf881c3010f8d15e (HEAD -> master, origin/master, origin/HEAD)" this version but may be this is not your correct version and your previous version was correct so you want to revert file with any previous, how?
[root@server106 html]# git reset  21506b4f838f8ee9a15adb0e71293abc9fe0bcf6 web.html
Unstaged changes after reset:
M       web.html
[root@server106 html]# git checkout -- web.html - here checkout means you are telling to git that I am want the data which was committed in a44404e6399b3f94755637fabf881c3010f8d15e this version.

Comments

Popular posts from this blog

error: db5 error(11) from dbenv->open: Resource temporarily unavailable

If rpm command is not working in your system and it is giving an error message( error: db5 error(11) from dbenv->open: Resource temporarily unavailable ). What is the root cause of this issue? How to fix this issue?   just a single command- [root@localhost rpm]# rpm --rebuilddb Detailed error message- [root@localhost rpm]# rpm -q firefox ^Cerror: db5 error(11) from dbenv->open: Resource temporarily unavailable error: cannot open Packages index using db5 - Resource temporarily unavailable (11) error: cannot open Packages database in /var/lib/rpm ^Cerror: db5 error(11) from dbenv->open: Resource temporarily unavailable error: cannot open Packages database in /var/lib/rpm package firefox is not installed [root@localhost rpm]# RPM manage a database in which it store all information related to packages installed in our system. /var/lib/rpm, this is directory where this information is available. [root@localhost rpm]# cd /var/lib/rpm ...

Failed to get D-Bus connection: Operation not permitted

" Failed to get D-Bus connection: Operation not permitted " - systemctl command is not working in Docker container. If systemctl command is not working in your container and giving subjected error message then simple solution of this error is, create container with -- privileged option and also provide init file full path  /usr/sbin/init [root@server109 ~]# docker container run -dit --privileged --name systemctl_not_working_centos1 centos:7 /usr/sbin/init For detailed explanation and understanding I am writing more about it, please have look below. If we have a daemon based program(httpd, sshd, jenkins, docker etc.) running inside a container and we would like to start/stop or check status of daemon inside docker then it becomes difficult for us to perform such operations , because by default systemctl and service  commands don't work inside docker. Normally we run below commands to check services status in Linux systems. [root@server109 ~]# systemctl status ...

AWS cloud automation using Terraform

In this post I'll create multiple resources in AWS cloud using Terraform . Terraform is an infrastructure as code( IAC ) software which can do lots of things but it is superb in cloud automation. To use Terraform we have write code in a high-level configuration language known as Hashicorp Configuration Language , optionally we can write code in JSON as well. I'll create below service using Terraform- 1. Create the key-pair and security group which allow inbound traffic on port 80 and 22 2. Launch EC2 instance. 3. To create EC2 instance use same key and security group which created in step 1 4. Launch Volume(EBS) and mount this volume into /var/www/html directory 5. Upload index.php file and an image on GitHub repository 6. Clone GitHub repository into /var/www/html 7. Create S3 bucket, copy images from GitHub repo into it and set permission to public readable 8 Create a CloudFront use S3 bucket(which contains images) and use the CloudFront URL to update code in /var/w...