How Does Git Work - Git Tutorial For Beginners
How Does Git Work - Git Tutorial For Beginners
KnowledgeBase
ANDROID
CORE JAVA
Deals
JobBoard
About
DESKTOP JAVA
ENTERPRISE JAVA
JAVA BASICS
JVM LANGUAGES
SOFTWARE DEVELOPMENT
Search...
DEVOPS
HomeSoftwareDevelopmentGitHowdoesGitwork?GitTutorialforBeginners
ABOUT JUN WU
Jun(Steven)WuisacurrentMasterstudentinComputerScience&EngineeringdepartmentofUniversityofNebraskaLincoln
(Lincoln,NE,USA).HiscurrentinterestsfocusonProgrammingLanguages(Java,Python),RelationalDatabase(MySQL),NoSQL
Database(ApacheCassandra,MongoDB),andComputerNetworks.
1.Introduction
Version Control Systems
areoneofthesoftwaretoolsthathelpdevelopersmanagethesourcecodeovertime.
Theykeeptrackofthemodification,comparedwithdifferentversionsofthesource
code.Asthenumberoflinesincreases,itcouldgouptothousandsandthousands
lines.
Inreallife,itcouldbeadisasterifwemakesomeirrecoverablemistakeswithoutany
backups.However,thiswillnothappenincodewritingforthedevelopers,especially
withthehelpof
Git
,whichisoneofthemostpopularsourcecodemanagementsystemforsoftwaredevelopment.
Git
NEWSLETTER
160768insidersarealreadyenjoying
weeklyupdatesandcomplimentary
whitepapers!
hasbeenwidelyusedamongprogrammers.
Jointhemnowtogainexclusive
accesstothelatestnewsintheJavaworld,
DoyouwanttoknowhowtodevelopyourskillsettobecomeaJava
Rockstar?
aswellasinsightsaboutAndroid,Scala,
Groovyandotherrelatedtechnologies.
SubscribetoournewslettertostartRockingrightnow!
TogetyoustartedwegiveyouourbestsellingeBooksforFREE!
Emailaddress:
Youremailaddress
Signup
1.JPAMiniBook
2.JVMTroubleshootingGuide
3.JUnitTutorialforUnitTesting
4.JavaAnnotationsTutorial
5.JavaInterviewQuestions
6.SpringInterviewQuestions
7.AndroidUIDesign
andmanymore....
Emailaddress:
Youremailaddress
Signup
ComparedwithotherVersionControlSystems,suchas
SVN
(ApacheSubversion)and
CVS
(ConcurrentVersionSystem),Gitismorepowerfulbyitsdistributednature,fastoperationandbranchhandlingmechanism.Thedistributed
JOIN US
With 1,240,600 monthly
uniquevisitorsandover
500 authorsweare
placedamongthetopJava
relatedsitesaround.
Constantlybeingonthe
lookoutforpartnerswe
encourageyoutojoinus.
SoIfyouhaveablogwith
uniqueandinterestingcontentthenyoushould
checkoutourJCGpartnersprogram.Youcanalso
beaguestwriterforJavaCodeGeeksandhone
yourwritingskills!
(ConcurrentVersionSystem),Gitismorepowerfulbyitsdistributednature,fastoperationandbranchhandlingmechanism.Thedistributed
systemmakesiteasyandefficientformultipledevelopersworktogethertowardsthesameproject.
Git
worksfastasitslightweightoperations.Alsoeverydevelopercanworkwiththecodeasitsownbranch.Otherscanmergetodifferent
branchesandthismakescooperationworkquiteeasy.Inaddition,
Git
isfreeandopensource.
Becauseoftheefficientof
Git
,
Github
,whichisthewebbasedrepositoryhostingserviceplatform,isalsopopularlyused.Youcanfindmanyusefulmaterials/codesin
Github
withthelinkhere.
Inthisarticle,wewillgooverthebasicprinciplesandoperationsof
Git
.AlltheexamplesbelowisshowninMacOSEICapitanVersion10.11.3andtheGitversionis2.5.4.Notealltheoperationsbelowisworking
onlocalmachine,withoutconnectingtoGithub.
2.Gitinstallation
Beforewedigintotheprinciplesandoperationsof
Git
,weneedtohavethetoolandinstall
Git
.Toinstall
Git
,twowayscouldbeused:
(1)Usethecommandline:Fordifferentoperatingsystems,differentcommandlinemaybeusedinterminal.Forexample,forlinux,
sudo yum install git-all
couldinstall
Git
successfully.Formoredetailedinstallationmethodsonothersystem,youcanfollowthetutorialhere.
(2)Usethepackage:Also,itseasierifyoucouldfindtheinstallationpackagesfor
Git
.Thenyoucandownloaditandeasilyinstallitbyclickthepackage.ItalsoprovidetheGUIfor
Git
,whichmakesituserfriendly.The
CAREER OPPORTUNITIES
REMOTESeniorJavaDeveloperABCFinancial
ServicesInc
Remote
Apr,04
SoftwareEngineerGoogle
MountainView,CA
Mar,24
ApplicationsDeveloper,JavaREMOTEThe
TatitlekCorporation
Dahlgren,VA
Apr,21
JavaSoftwareDeveloper,MidtoSenior
REMOTESpinSystems
UnitedStates
Apr,27
SoftwareEngineerGoogle
Boulder,CO
Mar,24
SoftwareEngineerGoogle
NewYork,NY
Mar,24
SoftwareEngineerGoogle
Cambridge,MA
Mar,24
SeniorSolutionsDeveloper(Java/Application
Development)MercedesBenz:Corporate
Opportunities
Atlanta,GA
Apr,25
SoftwareEngineerGoogle
Seattle,WA
Mar,24
AdvisorySoftwareEngineerJavaLenovo
Raleigh,NC
Apr,20
1
...
6942
Git
Freelance
communityprovidesinformationfordifferentsystems,suchasMacOS,Windows,LinuxandSolaris.Fordetailedpackagesdownload,youcan
refertothelinkhere.
3.Basicconceptsandprinciples
Firstly,weneedtogetusedtotherepositoryconcepts.In
Git
,therewillbethreerepositoriesorareas.Ifweconsidertheusageof
Github
,thenweneedtounderstandtheremoterepository.Tomakeitclear,weusethefollowingflowtodemonstratehowthegitworks.
Keyword...
Location...
Country...
FilterResults
jobsby
Fulltime
Intership
Parttime
All
Gitworkingflow
Workspace:itstheplacewhereyouseeinyourcomputersystem,orthedirectorywhereyoucheckoutyourfiles.Filesintheworkspace
couldbeaddedtotheGitbyusing
git add
command.Basicallyitcouldbeanyfoldersinyourcomputer.
Index:itsalsocalledstatingarea.Itsaninvisiblespacewhereyoucanaddfilesthatyouwanttocommit.Toaddcommit,youcanuse
git commit
command.
Localrepository:itsalsoaninvisiblerepository.Actuallyitsstoredinthe.gitfolder,whichishiddeninthefolderyoucreated.
Remoterepository:thiscouldbeanothercomputer,oritcouldbetheserverofothers,suchasGithub,whichwecanconsideritasa
remoterepository.Toaccesstotheremoterepository,gitpushor
git pull
couldbeused.
Inaddition,wealsoneedtobefamiliarwithsomeothercommonconceptsin
Git
.
Branch:itsusedtocreateanotherlineofcode.Usuallyitsforcreatinganothernewfeature.Oncethenewfeaturehascompleted,itcan
bemergedbackthethemasterbranch.
MasterBranch:wecanconsideritasthemainbranch/codetoworkon.Youcanaddotherbranchesifneeded.Butthewholeprojectcan
onlyhaveonemasterbranch.
Commit:itholdsthecurrentstateoftherepository.Itcanbeconsideredasanodeofalinkedlist.Everycommithasapointertothe
parentcommitobject.Youcangobacktotheparentcommitobjectbychangingthepointer.
HEAD:itisthepointertothemostrecentcommitonthecurrentbranch.Itsactuallyahashvalueofcurrentcommit,whichiscalculated
bySHA1hashonafilewithahashvalueof160bitsthatuniquelyidentifiesthecontentsofthefile.
4.Gitoperations
Afterweunderstandtherepositoriesandbasicconceptsof
Git
,wewillmovetotheoperationsof
Git
.
Beforewegotothedetailedexample,makesuregitisinstalledonyourcomputer/laptop.Thenopentheterminal,trytorun
git --version
,youwillseetheversionoftheGityouveinstalledasbelow:
1 WXMsMacBookPro:~WXM$gitversion
2 gitversion2.6.4(AppleGit63)
Tohaveabasicideaofwhatcommandyouregoingtouse,youcanrefertothetablebelow:
gitcommand
functions
gitinit
createanewlocalrepository
gitclone
downloadaprojectanditsentireversionhistory
gitadd
addfiletothestatingarea
gitcommit
addfilefromstagingareatolocalrepository
gitstatus
listallnewormodifiedfilestobecommited
gitdiff
showfilesdifferencestobestaged
gitlog
listversionhistoryforcurrentbranch
gitrm
deletefilefromtheworkingdirectory
gitreset
undocommitsandchangebacktospecifiedone
gitpush
uploadalllocalbranchcommitstogithub
gitpull
downloadbookmarkhistoryandincoorparateschanges
4.1gitinitcommand
Aftercheckingtheinstallationof
Git
,weneedtocreateafolderinourcomputer.SowecreateablankfoldernamedGitTutorial.Thengointothefolderandtypecommand
git init
.Thiscommandwillchangethisfoldertobearepositorywhichyoucanmanage.Also,theoutputafteryoutype
git init
showsthatyouvesuccessfullycreatedandinitializedanemptygitrepository.Afterrunning
ls -ah
,youwillseetheresa.gitfolderinsidetheGitTutorialfolder.Thisfolderisutilizedtotrackthegitfolder.Makesureyouwontchangeit,
whichmayleadtoerrorshappeningtothewholegitfolder.Alsonotethat.gitfolderishiddenbydefault,andyoucanusetheprevious
ls -ah
commandtomakeitvisible.
Foralltheseoperations,youcanchecktheresultbelow:
1
2
3
4
5
6
7
WXMsMacBookPro:~WXM$cdDocuments/
WXMsMacBookPro:DocumentsWXM$cdGitTutorial/
WXMsMacBookPro:GitTutorialWXM$ls
WXMsMacBookPro:GitTutorialWXM$gitinit
InitializedemptyGitrepositoryin/Users/WXM/Documents/GitTutorial/.git/
WXMsMacBookPro:GitTutorialWXM$lsah
....git
4.2gitaddcommand
Secondly,wecanuseatextfileasanexampleinusageofGit.InsidetheGitTutorialfolder,createanemptytxtfilewithnameGitExample.txt.
Thenaddanywordsinitwith:ThisisatxtfileforGitExample.
Lastly,weneedtoaddtheGitExamplefileintotheGitsystem.Thenrun
git add GitExample.txt
.Thiscommandwilladdthetxtfiletothestagingarea,whichisamiddleareabetweenworkspaceandthelocalrepository.
1
2
3
4
5
6
WXMsMacBookPro:GitTutorialWXM$viGitExample.txt
WXMsMacBookPro:GitTutorialWXM$ls
GitExample.txt
WXMsMacBookPro:GitTutorialWXM$catGitExample.txt
ThisisatxtfileforGitExample.
WXMsMacBookPro:GitTutorialWXM$gitaddGitExample.txt
4.3gitcommitcommand
Then,weneedtoaddthisfilefromstagingareatolocalrepository.Toachievethis,wecanrun
git commit -m "First time writing the txt file"
.Notethestringaftermisthecommentthatwemakebyourselves.Itcanbeanythingyouwanttocomment.Belowshowstheresultsofall
theseoperations.
1
2
3
4
WXMsMacBookPro:GitTutorialWXM$gitcommitm"Firsttimewritingthetxtfile"
[master(rootcommit)9f3fca6]Firsttimewritingthetxtfile
1filechanged,1insertion(+)
createmode100644GitExample.txt
4.4gitstatuscommand
Afterward,wecancheckthestatusofthewholefolderwithcommand
Afterward,wecancheckthestatusofthewholefolderwithcommand
git status
.Thenitseemstobeeverythingiffineuntilnow.
1 WXMsMacBookPro:GitTutorialWXM$gitstatus
2 Onbranchmaster
3 nothingtocommit,workingdirectoryclean
4.5gitdiffcommand
Themainpurposefor
git diff
commandistoshowchangesofthefilebetweencommits,commitandworkingtree,etc.
Tomakeitwork,weneedtocreatesomedifferences.Asastart,wemodifythecontentintheGitExample.txtfileandaddonemorelinewith
Onemoreline.Thecontentinsidethetxtfilenowis:
1 ThisisatxtfileforGitExample.
2 Onemoreline.
Afterthis,wecanruncommand
git diff
tocheckthedifferencebetweenthecurrentversionwiththepreviousone,theoutputis:
1
2
3
4
5
6
7
8
WXMsMacBookPro:GitTutorialWXM$gitdiff
diffgita/GitExample.txtb/GitExample.txt
index30e6813..8c7c8d2100644
a/GitExample.txt
+++b/GitExample.txt
@@1+1,2@@
ThisisatxtfileforGitExample.
+Onemoreline.
Thenwecanseethatthesentencewith+showsthatwhereweaddsomecontentstothefile.Alsowecanpredictthatoperationshows
wedeletesomecontentsfromthefile.
ThenifwemadeanotherchangetothethetxtfileandaddanotherlinewithIlovechangingthings.Untilnowwevemadethreechanges
addingthreelinescomparedwiththefirstversion.Thefourcommitsare:Lovemakingchanges<Madechangesagain<Addbadwords<
Firsttimewritingreadmefile,wherethearrowshowstheorderofthechanges.
Anotherusefulgitdiffcommandis
git diff --cached
,itllshowthedifferencesbetweentheindexandthemostrecentcommit.Afterrunningthiscommandinourexample,itsowsnothing.The
reasonforthis,isthatuntilnow,theresnodifferencebetweentheindexandmostrecentcommit.
Thenifwewanttocheckthedifferencebetweentheworkingdirectoryandhemostrecentcommit,
git diff HEAD
couldbeused.
Here,wecheckthestatusofourcurrentsystem,withthehelpof
git status
:
1
2
3
4
5
6
7
8
9
WXMsMacBookPro:GitTutorialWXM$gitstatus
Onbranchmaster
Changesnotstagedforcommit:
(use"gitadd..."toupdatewhatwillbecommitted)
(use"gitcheckout..."todiscardchangesinworkingdirectory)
modified:GitExample.txt
nochangesaddedtocommit(use"gitadd"and/or"gitcommita")
Ifweaddthetxtfiletotheindexwithcommand
git add GitExample.txt
,thenrunthe
git diff
,itshowsnothing.Thatsbecauserightnowthecontentintheworkingdirectoryandtheindexarethesame.Thistime,werunthecommand
git diff --cached
,itshowsthecontentbelowinsteadofshowingnothingasprevious.
1
2
3
4
5
6
7
8
WXMsMacBookPro:GitTutorialWXM$gitdiffcached
diffgita/GitExample.txtb/GitExample.txt
index30e6813..8c7c8d2100644
a/GitExample.txt
+++b/GitExample.txt
@@1+1,2@@
ThisisatxtfileforGitExample.
+Onemoreline.
Tocheckthestatus,runcommand
git status
:
1
2
3
4
5
6
WXMsMacBookPro:GitTutorialWXM$gitstatus
Onbranchmaster
Changestobecommitted:
(use"gitresetHEAD..."tounstage)
modified:GitExample.txt
Untilnow,theresstilldifferencebetweentheindexandthemostrecentlycommit.Itcanbeprovedbyrunning
git diff HEAD
1
2
3
4
5
6
7
8
WXMsMacBookPro:GitTutorialWXM$gitdiffHEAD
diffgita/GitExample.txtb/GitExample.txt
index30e6813..8c7c8d2100644
a/GitExample.txt
+++b/GitExample.txt
@@1+1,2@@
ThisisatxtfileforGitExample.
+Onemoreline.
However,afterwecommitthefileandrerunthepreviouscommandagain,itshowsnothing.
1 WXMsMacBookPro:GitTutorialWXM$gitcommitm"Addonemoreline"
2 [mastercb3db9a]Addonemoreline
3 1filechanged,1insertion(+)
Also,thestatusisclearrightnow,ifwerunthecommand
git status
,itshowseverythingisclear:
1 WXMsMacBookPro:GitDiffExampleWXM$gitstatus
2 Onbranchmaster
3 nothingtocommit,workingdirectoryclean
4.6gitlogcommand
Inreallifeofdevelopment,thousandslinesofcodecouldbechanged.Wecannotrememberitexactly.So
git log
shouldbeusefulrightnow,anditllshowallthechangehistorywehavemade.Wecantryitwithourownexamplehereafterwemadethree
commitsinourpreviouspart:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
pcp352933pcs:GitTutorialWXM$gitlog
commit67713e5af45b67aa2628b12a73d4b493a16de159
Author:Jun
Date:SunApr2417:19:1220160500
Lovemakingchanges
commit47640c18cf433c6f6c7ba26b34f886688d34a1d3
Author:Jun
Date:SunApr2417:18:3820160500
Madechangesagain
commit1f50e80eb551e3ed7981251378d4609e30248d2f
Author:Jun
Date:SunApr2416:58:2120160500
Addbadwords
commitd90715179d20e10c5d88fc8d8a58972605fb38c0
Author:Jun
Date:SunApr2416:32:2820160500
Firsttimewritingreadmefile
Theabovefileshowseverychangewevemadewithspecificdateandtime.Youshouldnoticethelongsequenceofstringsafterthecommit.
Thatsthecommitid,whichcorrespondstospecificcommit.Whyitsnotin1,2,3order?ThatsbecauseGitisadistributedsystem.Ifevery
commitidisinorder,whenmultiplechangeshappen,thereshouldbeconflict.
Sometimes,thechangesarequitealotandwhatwewantisjusttocheckthechanges.Then
git log --pretty=oneline
couldbeutilizedtoshoweachcommitinoneline.
1
2
3
4
5
pcp352933pcs:GitTutorialWXM$gitlogpretty=oneline
67713e5af45b67aa2628b12a73d4b493a16de159Lovemakingchanges
47640c18cf433c6f6c7ba26b34f886688d34a1d3Madechangesagain
1f50e80eb551e3ed7981251378d4609e30248d2fAddbadwords
d90715179d20e10c5d88fc8d8a58972605fb38c0Firsttimewritingreadmefile
4.7Gitundooperation
Insomecases,wewanttochangeourmindsandrevertthecommitwehavemade,then
Git
makesthiseasytooperateon.Thisiscalled
makesthiseasytooperateon.Thisiscalled
git undo commit
.Tomakethishappen,weaddanotherlinetotheGitExample.txt,withBadwordsforothers.Thenweaddthefiletothestatingareaandto
thelocalrepository.Thefollowingistheprocessthatwehavedone:
1
2
3
4
5
6
7
pcp352933pcs:GitTutorialWXM$gitaddGitExample.txt
pcp352933pcs:GitTutorialWXM$gitcommitm"Addbadwords"
[master1f50e80]Addbadwords
1filechanged,1insertion(+)
pcp352933pcs:GitTutorialWXM$catGitExample.txt
ThisisatxtfileforGitExample.
Badwordsforothers.
Ifwewanttogobacktothepreviousversion,gitresetcommandcouldbeused.WhatweusehereisgitresethardHEAD^.HEADismeans
thecommitofcurrentbranch.Symbol^meansgobacktothepreviousoneversion,^^meanstheprevioustwoversionandsoonso
forth.Whileitshardtocontinuewithmultiple^symbolswhenthereshundredsandthousandsversions.
Thenyoucanusethenumberdirectly.ForexamplegitresethardHEAD^isthesameasgitresethardHEAD~1andgitresethard
HEAD^^isthesameasgitresethardHEAD~2.Payattentiontothesymbol~beforethenumbersanddonotforgettoaddit.
Forourownexample,rightnowtheheadisin67713e5af45b67aa2628b12a73d4b493a16de159Lovemakingchanges.Ifwewanttogobackto
thepreviousversion.RunthegitresethardHEAD^commandandchecktheresult.
01
02
03
04
05
06
07
08
09
10
11
pcp352933pcs:GitToturialWXM$catGitExample.txt
ThisisatxtfileforGitExample.
Badwordsforothers.
Imadechangesagain:)
Ilovechangingthings.
pcp352933pcs:GitTutorialWXM$gitresethardHEAD^
HEADisnowat47640c1Madechangesagain
pcp352933pcs:GitTutorialWXM$catGitExample.txt
ThisisatxtfileforGitExample.
Badwordsforothers.
Imadechangesagain:)
Wecanseefromtheabove,thatafterwerunthe
git reset
command,itgoesbacktothepreviousversionMadechangesagain.The47640c1isexactlytheshortcutcommitidforthepreviouscommit.
Thenifwewanttogobacktotheinitialstatus,wecangobacktwicewithcommand
git reset --hard HEAD~2
1
2
3
4
pcp352933pcs:GitTutorialWXM$gitresethardHEAD~2
HEADisnowatd907151Firsttimewritingreadmefile
pcp352933pcs:GitTutorialWXM$catGitExample.txt
ThisisatxtfileforGitExample.
Thenrun
git log
,itshowsonlythefirstversion.
1
2
3
4
5
6
7
8
pcp352933pcs:GitTutorialWXM$gitlog
commitd90715179d20e10c5d88fc8d8a58972605fb38c0
Author:Jun<[email protected]>
Date:SunApr2416:32:2820160500
Firsttimewritingreadmefile
pcp352933pcs:GitTutorialWXM$catGitExample.txt
ThisisatxtfileforGitExample
However,ifonedaywefindthatthelinesweaddedareuseful,couldwegofurtherandgetitback?Yes,wecan!Iftheterminalisnotclosed,
weneedtofindthecommitnumberwhichtheversionis.Forexample,thecommitnumberforLovemakingchangesversionis
67713e5af45b67aa2628b12a73d4b493a16de159.Thenwecanusethe
git reset --hard
commandwiththecommitidfollowingit.Notethatwecanusethefirstfewnumbersofthecommitidinmostcase.
1
2
3
4
5
6
7
pcp352933pcs:GitTutorialWXM$gitresethard67713e5a
HEADisnowat67713e5Lovemakingchanges
pcp352933pcs:GitTutorialWXM$catGitExample.txt
ThisisatxtfileforGitExample
Badwordsforothers.
Imadechangesagain:)
Ilovechangingthings.
Yousee,itsback.However,makesureyoureallywanttogobackandforce.Insomecases,ifyoudontknowthecommitid,youwontcome
backtothenewestversion.
Insomecases,thatyoureallywanttocomebacktothenewestversion.Then
git reflow
couldbeusefulforyou,whichwilltrackeverycommandyouvemade.Runthecommandandyoullgetsomethingmagic.
1
2
3
4
5
6
7
8
9
pcp352933pcs:GitTutorialWXM$gitreflog
d907151HEAD@{0}:reset:movingtoHEAD^^^
67713e5HEAD@{1}:reset:movingto67713e5a
d907151HEAD@{2}:reset:movingtoHEAD~2
47640c1HEAD@{3}:reset:movingtoHEAD^
67713e5HEAD@{4}:commit:Lovemakingchanges
47640c1HEAD@{5}:commit:Madechangesagain
1f50e80HEAD@{6}:commit:Addbadwords
d907151HEAD@{7}:commit:Firsttimewritingreadmefile
Herewehaveallthecommitnumbertoeachcommitandeachreset/undooperation.Soyoudontneedtoworryaboutwhereyourenow.
Tomakeitmorecleartounderstand,wecanusethefollowingfiguretoshowhowitwork.TheHEADworksasapointertopointtospecific
version.Forexample,ifHEADispointertothelastversion.Thenafterusingtheresetcommand,wecangobacktheinitialversion.
Gitundotoversion1
Gitundotoversion4
Aswecanseefromthepreviousfigure,itsquiteeasyforustochangetodifferentversionsofourcode.Itsjustanoperationofcommand.
4.8gitrmoperation
Also,itcouldbepossibleforustodeletethecodeinourdirectory.Forexample,
git rm
withthefilenamefollowingthecommand.Thiscommandwilldeletethefilefromtheworkingdirectoryandstagesthedeletion.
Ifweusethe
git rm --cached
withthefilenamefollowingthecommand,itwillremovethefilefromtheversioncontrolbutpreservesthefilelocally.
Noticethatwedonotrecommendittousethiscommandoften.Thereasonforthisisthatthisdeletionmaybeunrecoverable.Abetter
approachcouldbemakeadifferentbranchandworkonthatbranch.
5.Githubconnection
Lastly,weintroduce
Github
briefly.Toconnectwith
Github
,weneedtohavea
Github
accountfirstly.Youcangotogithub.comandregisteroneforyourself.
Afterthis,youcanfollowthelinktoconnectto
Github
.Thenyoucanupload/pushanddownload/pullthechangestothe
Github
server.
Afterthepreviousoperationsof
,use
git push
command,itwillpublishthelocalchangestotheremoterepository.Forexample,thefollowingshowshowitlooksafterwepushourcodeto
theserver:
1
2
3
4
5
6
7
pcp352933pcs:GitTutorialWXM$gitpush
Countingobjects:3,done.
Deltacompressionusingupto4threads.
Compressingobjects:100%(2/2),done.
Writingobjects:100%(3/3),309bytes|0bytes/s,done.
Total3(delta1),reused0(delta0)
Tohttps://github.com/******/GitTutorial.git
8 5a5a9ea..d907151master>master
Now,otherdeveloperscanviewthechangesbyperformingpull/cloneoperationorupdatingtheirlocalrepository.Thiswilldownloadthecode
inservertolocaldirectoryandworkonit.Itcanbeachievedby
git clone
withtheURLthatontheserver.
Thefollowingwillshowyouhowitworks:
1
2
3
4
Cloninginto'test_repo'...
remote:Countingobjects:3,done.
remote:Total3(delta0),reused3(delta0)
Unpackingobjects:100%(3/3),done.
6.Conclusion
Inconclusion,
Git
isaveryusefultoolforsoftwaredevelopers.Oneshouldunderstandtheprincipleofitanduseitoften.Also,youcanfindmanyuseful
materialsin
Github
andyoumaywanttocontributetosomeopensources.
DoyouwanttoknowhowtodevelopyourskillsettobecomeaJava
Rockstar?
SubscribetoournewslettertostartRockingrightnow!
TogetyoustartedwegiveyouourbestsellingeBooksforFREE!
1.JPAMiniBook
2.JVMTroubleshootingGuide
3.JUnitTutorialforUnitTesting
4.JavaAnnotationsTutorial
5.JavaInterviewQuestions
6.SpringInterviewQuestions
7.AndroidUIDesign
andmanymore....
Emailaddress:
Youremailaddress
Signup
KNOWLEDGE BASE
HALL OF FAME
KNOWLEDGE BASE
HALL OF FAME
Courses
AndroidAlertDialogExample
News
AndroidOnClickListenerExample
Resources
HowtoconvertCharactertoStringanda
Tutorials
Whitepapers
StringtoCharacterArrayinJava
JavaInheritanceexample
JavawritetoFileExample
java.io.FileNotFoundExceptionHowto
solveFileNotFoundException
DISCLAIMER
AlltrademarksandregisteredtrademarksappearingonJavaCodeGeeksarethe
propertyoftheirrespectiveowners.Javaisatrademarkorregisteredtrademarkof
OracleCorporationintheUnitedStatesandothercountries.ExamplesJavaCodeGeeks
isnotconnectedtoOracleCorporationandisnotsponsoredbyOracleCorporation.
java.lang.arrayindexoutofboundsexception
HowtohandleArrayIndexOutOf
BoundsException
java.lang.NoClassDefFoundErrorHowto
solveNoClassDefFoundError
JSONExampleWithJersey+Jackson
SpringJdbcTemplateExample
ExamplesJavaCodeGeeksandallcontentcopyright20102016,ExelixisMediaP.C.|TermsofUse|PrivacyPolicy|Contact