Devops Exercise-4
Devops Exercise-4
Modulename:ImplementationofCICDwithJavaandopen-sourcestack
ConfigurethewebapplicationandVersioncontrolusingGitusingGitcommandsand version
control operations.
Whatis GIT?
Git is a free open-source distributed version control system you can use to track
changesinyourfiles.YoucanworkonalltypesofprojectsinGit,fromsmalltolarge.
WithGit,youcanaddchangestoyourcodeandthencommitthem(orsavethem)when you're
ready. This means you can also go back to changes you made before.
GitworkshandinhandwithGitHub–sowhatisGitHub?
WhatisGitHub?
GitHubisawebinterfacewhereyoustoreyourGitrepositoriesandtrackandmanage
yourchanges effectively.Itgivesaccess tothecodetovariousdevelopersworkingon the
same project. You can make your own changes to a project at the same time as other
developers are making theirs.
WhyuseGitHub
There are so many reasons you should learn and use GitHub. Let's look at a few of
them now.
EffectiveProjectManagement
GitHub is a place where your Git repositories are stored. GitHub makes it easy for
developers working on the same project but in different locations to be on the same
page.
DepartmentofCSE pg.21
EasyCollaborationandCooperation
Teams are able to stay on the same page while working on a project together and can
easily organize and manage the project effectively.
Open Source
GitHubisafreeandopen-sourcesystem.Thismeansthatdeveloperscaneasilyaccess
different types of code/projects which they can use in learning and developing their
skills.
Versatility
This attribute of GitHub is very important. GitHub is not a web interface for only
developers. It can be used by designers, writers, and anyone who wants to keep track
of the history of their projects.
HowtoSetupGit
When Git opens, scroll down a bit and you should see a download button. Go ahead
and click on it.Download button on the Git website
Chooseyouroperatingsystemwhetherit'sWindows,MacOS,Linux/Unix.Inmy case,
I will be choosing the Windows option because I am using a Windows computer:
DepartmentofCS E 22
fCSE
Chooseyouroperatingseeyousystem
ClickonthefirstlinkattheverytopofthepagetodownloadthelatestversionofGit.
DownloadthelatestversionofGitbyclickingthefirstlink
Whenthedownloadiscomplete,thengoaheadandinstallGittoyourcomputer.You'll need
to go to the location where the file has been downloaded and install it.
Aftertheinstallation,you'llwanttomakesurethatGitissuccessfullyinstalledonyour
system. Open your command prompt or Git bash (whichever one you choose to use)
and run the command:
DepartmentofCSE pg.23
git--version
IfGitwassuccessfullyinstalledonyourcomputer,itshoulddisplaythecurrentversion of Git
below the command you just ran. If the current version is being displayed,
congratulations!
HowtoConfigureGit
Now that we have installed Git on our computer, we have to configure it. We do this
so that any time we are working in a team on a project, we can easily identify the
commits we have made in the repository.
To configure Git, we need to specify the name, email address, and branch by usingthe
git config --global command. For example:
From the image above, we used git config --global user.name to configure the
username.InmycaseIusedmyname “DerekEmmanuel”.Thesameappliesforthe git
config --global user.email.
DepartmentofCSE pg.24
Howto Setupa GitHubAccount
TosetupaGitHubaccount,visittheir officialwebsite.Clickonthesign upbuttonin
the upper right corner:
Whenthesignupformopensup,enteryouremail,createapassword,enteryour
username, and then verify your account before clicking on the create account
button.
CreateyourGitHubaccount
CommonlyUsedGitCommands
TherearesomebasicGitcommandsthateverydevelopershouldknowhowtouse:
gitconfig
gitinit
gitadd
gitcommit
gitclone
git push
gitrm
gitbranch
Let'sgothrougheachofthesebrieflysoyouknowhowtousethem.
HowtoUsethegitconfigCommand
Youusethiscommandtosettheusername,email,andbranchofausersoastoidentify
whomadeacommitwhenworkingonaproject.Thiscommandisusedwhenyouhav
e downloaded git into your computer and you want to customize it for your
use.
Forexample:
gitconfig--globaluser.name“[username]”
gitconfig--globaluser.Email[emailaddress]
HowtoUsethegitinitCommand
You use the git init command to start Git in your project. This git command
is used
whenyouareworkingonaprojectandwouldliketoinitializegittotheprojectinorder
to keep track of the changes made in the project.
Forexample:itinit
Whenyourunthiscommand,youshouldseeafoldernamed.gitbeingcreatedautomatic
ally in the current folder you are working on.
HowtoUsethegitaddCommand
This command adds your file to the staging area. The staging area is the area
where files we make changes to are added and where they wait for the next
commit.
To add a file to the staging area, you use the git add command. It adds all the files in the folder to the
staging area.
gitadd(filename)addsthenameoftheparticularfileyouwanttocommitinthe staging
area.
Usethiscommandwhenyouhavemadechangestoafileandwanttocommitthemto
your project.
HowtoUsethegitcommitCommand
Thiscommitsanyfileyouaddedwiththe gitaddcommandaswellaseveryfileinthe
staging area.
Forexample:
gitcommit–m“firstcommit”
This command saves a file permanently to the Git repository. You use it
whenever a file has been added to the staging area using the git add
command.
HowtoUsethegitcloneCommand
Forexample:
gitclone(repositoryname)
YouusethiscommandwhenyouwanttoduplicateaGitrepositoryfromGitHubinto
your local storage.
HowtoUsethegitpushCommand
Youusethiscommandtoupload/pushfilesfromthelocalrepository/storagetoanother
storage, like a remote storage such as GitHub.
Forexample:
gitpush(remotestoragename)
Youonlyusethiscommandwhenyou'resatisfiedwiththechangesandcommitsyou've
made on a project and finally want to upload/push it to the Git repository in
GitHub.
HowtoUsethegitrmCommand
YouusethisGitcommandtoremoveafilefromaworkingrepository.Forexample:
git rm (filename)
Youusethiscommandonlywhenyouwishtogetridofanunwantedchanges/
filefrom the Git repository.
HowtoUsethegitbranch Command
Forexample:
gitbranch
Thiscommandhelpsyouknowthecurrentbranchyouareworkingon.
Conclusion
Inthistutorialyoulearnedwhatversioncontrolsystemsareallabout.Youalsolearn
ed
howtoinstallandsetupGitonyourcomputerandsetupaGitHubaccount.Lastly,we
went through some commonly used Git commands.