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:-
Linux :-
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)
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
Post a Comment
Please share your experience.....