0% found this document useful (0 votes)
67 views2 pages

Git Commands: New Bare Repository

$ git init initializes a local Git repository. $ git clone clones an existing repository from a server to your local machine. $ git add stages files' contents for the next commit. $ git commit permanently stores file changes in the project's history with a commit message. $ git push uploads local commit history to a remote repository.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views2 pages

Git Commands: New Bare Repository

$ git init initializes a local Git repository. $ git clone clones an existing repository from a server to your local machine. $ git add stages files' contents for the next commit. $ git commit permanently stores file changes in the project's history with a commit message. $ git push uploads local commit history to a remote repository.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

GitCommands

[SettingUp]
$sudoaptgetinstallgit=>installingGitonLinuxDebianbaseddistributions(UbuntuMint)
$gitinit=>settinguparepository,transformthecurrentdirectoryintoaGitrepository
$gitinit<directory>=>createanemptyGitrepositoryinthespecifieddirectory
$gitinitbare<directory>=>initializeanemptyGitrepository,butomittheworkingdirectory
[Cloning]
$gitclone<repository><directory>=>clonetherepositorylocatedat"repository"intothefoldercalled"directory"onthelocalmachine
$gitclonebare<repository><baredirectory>=>toinitiallysetupanyGitserver,youhavetoexportanexistingrepositoryintoa
newbarerepository
[Configuring]
$gitconfiguser.email"<user@email>"=>definetheauthoremailtobeusedforallcommitsinthe"currentrepository"
$gitconfigglobaluser.name"UserName"=>settingyouridentity,tosetyourusernameforcurrentuser
$gitconfigglobalalias.<aliasname><gitcommand>=>createashortcutforaGitcommand
$gitconfigglobaledit=>opentheglobalconfigurationfileinatexteditorformanualediting
$gitconfigsystemalias.<aliasname><gitcommand>=>createshortcutsforGitcommands(forwholesystem)
$gitconfigglobalalias.ststatus|$gitconfigglobalalias.cocheckout|$gitconfigglobalalias.brbranch
$gitconfigglobalalias.uprebase|$gitconfigglobalalias.cicommit
$gitconfiglist=>checkingyoursettings
[Savingchanges]
$gitadd.=>begintrackingallfiles
$gitadd<fileordirectory>=>stageallchangesin"fileordirectory"forthenextcommit
$gitaddp=>beginaninteractivestagingsessionthatletsyouchooseportionsofafiletoaddtothenextcommit
$gitcommit=>committingyourchanges,committhestagedsnapshot
$gitcommitm<comment>=>totypeacommitmessage,commitsthestagedsnapshottotheprojecthistorywithamessageor
comment
$gitcommita=>automaticallystageeveryfilethatisalreadytrackedbeforedoingthecommit,commitasnapshotofallchangesinthe
workingdirectory
$gitcommitam<comment>=>commitallchangesandaddacomment
$gitrm=>toremoveitfromyourtrackedfiles&andalsofromyourworkingdirectory
$gitrmcached<filename>=>tokeepthefileinyourworkingtreebutremoveitfromyourstagingarea
[Inspecting]
$gitstatus=>checkingthestatusofyourfiles,displaysthestateoftheworkingdirectoryandthestagingarea(listwhichfilesare
staged,unstaged,anduntracked)
$gitlog=>displayshistoryofcommittedsnapshots
$gitlogn<limit>=>limitthenumberofcommitsby"limit"
$gitlogoneline=>condenseeachcommittoasingleline(tofindtheIDoftherevisionyouwanttosee)
$gitlogonelinedecorate=>showswherethebranchpointersarepointing
$gitlogstat=>includewhichfileswerealteredandtherelativenumberoflinesthatwereaddedordeletedfromeachofthem
$gitlogauthor="<pattern>"=>searchforcommitsbyaparticularauthor
$gitlog<file>=>onlydisplaycommitsthatincludethespecifiedfile
$gitreflog=>keepstrackofupdatestothetipofbranches(everytimethecurrentHEADgetsupdated)
[Branching]
$gitbranch=>listallavailablelocalbranches
$gitbranch<newbranchname>=>creatinganewbranch
$gitbranchd<branchname>=>deleteabranch
$gitbranchD<branchname>=>forcedeletethespecifiedbranch,evenifithasunmergedchanges
$gitbranchm<newbranchname>=>renamethecurrentbranchto"branch"
$gitbranchv=>seethelastcommitoneachbranch
$gitbranchvv=>toseewhattrackingbranchesyouhavesetup
$gitcheckout<branchname>=>switchtoanewbranchcontextchangecontextsthatyouareworkingin
$gitcheckoutb<newbranchname>=>createandimmediatelyswitchtoabranch,basedonthecurrentbranch
$gitcheckoutb<newbranch><existingbranch>=>createandswitchtothenewbranch,basedonanexistingbranch
$gitcheckoutb<localbranch><remotebranch>=>settingupmainlocalbranchestotrackremotemainbranches,settingupalocal
branchtotrackaremotebranch
[Merging]
$gitmerge<branch>=>mergethespecifiedbranchintothecurrentbranch
$gitmergenoff<branch>=>mergethespecifiedbranchintothecurrentbranch,butalwaysgenerateamergecommit
$gitmergesquash<workingbranch>=>takeallthecommitsfrom"workingbranch"andsquashthemmergingwiththecurrent
branch(tomakeallchangesinonecommit)

[Undoingchanges]
$gitcheckout<commit><file>=>turnsthe"file"thatresidesintheworkingdirectoryintoanexactcopyoftheonefrom"commit"and
addsittothestagingarea(awaytorevertbacktoanoldversionofanindividualfile)
$gitcheckoutHEAD<file>=>ifyoudontwanttokeeptheoldversion,youcancheckoutthemostrecentversion
$gitcheckout<commit>=>updateallfilesintheworkingdirectorytomatchthespecifiedcommit
$gitcheckout<file>=>todiscardchangesinworkingdirectory
$gitrevert<commit>=>generateanewcommitthatundoesallofthechangesintroducedin"commit",thenapplyittothecurrent
branch
$gitrevertHEAD=>revertthecommitwejustcreated
$gitreset=>resetthestagingareatomatchthemostrecentcommit,butleavetheworkingdirectoryunchanged
$gitreset<file>=>removethespecifiedfilefromthestagingarea,butleavetheworkingdirectoryunchanged
$gitresethard=>resetthestagingareaandtheworkingdirectorytomatchthemostrecentcommit
$gitreset<commit>=>movethecurrentbranchtipbackwardto"commit",resetthestagingareatomatch,butleavetheworking
directoryalone.Allchangesmadesince"commit"willresideintheworkingdirectory
$gitresethard<commit>=>movethecurrentbranchtipbackwardto"commit"andresetboththestagingareaandtheworking
directorytomatch
$gitclean=>removesuntrackedfilesfromyourworkingdirectory
$gitcleanf=>thiswillnotremoveuntrackedfoldersorfilesspecifiedby.gitignore.
$gitcleandf=>removeuntrackedfilesanduntrackeddirectoriesfromthecurrentdirectory
$gitcleanxf=>removeuntrackedfilesfromthecurrentdirectoryaswellasanyfilesthatGitusuallyignores
[Rewritinghistory]
$gitcommitamend=>aconvenientwaytofixupthemostrecentcommit.itletsyoucombinestagedchangeswiththeprevious
commitinsteadofcommittingitasanentirelynewsnapshot
$gitcommitamendnoedit=>tomaketheamendmenttoyourcommitwithoutchangingitscommitmessage
$gitrebase<base>=>rebasethecurrentbranchonto<base>
$gitrebasei<base>=>rebasethecurrentbranchonto<base>,butuseaninteractiverebasingsession(howindividualcommitswillbe
transferredtothenewbase)
[CollaboratingSyncing]
$gitbranchr=>toviewonlyyourremotebranches
$gitremote=>listtheremoteconnectionsyouhavetootherrepositories,toseewhichremoteserversyouhaveconfigured
$gitremotev=>includetheURLofeachconnection,showsyoutheURLsthatGithasstoredfortheshortnametobeusedwhen
readingandwritingtothatremote
$gitremoteadd<shortname><remoterepository>=>createanewconnectiontoaremoterepository,addingremoterepositories
$gitremoterm<name>=>removetheconnectiontotheremoterepositorycalled"name"
$gitremoterename<oldname><newname>=>renamearemoteconnectionfrom<oldname>to<newname>
$gitremoteshow<remotename>=>inspectingaremote(toseemoreinformationaboutaparticularremote)
$gitfetch<remotename>=>fetchallofthebranchesfromtherepository,fetchingfromyourremotes(togetdatafromyourremote
projects)
$gitfetch<remote><branch>=>onlyfetchthespecifiedbranch
$gitpull<remote>=>fetchthespecifiedremotescopyofthecurrentbranchandimmediatelymergeitintothelocalcopy
$gitpullrebase<remote>=>pullingremotecurrentbranchusingrebasemethod
$gitpullrebase<remote><branch>=>moveallofcommitstothetipofthebranchaftersynchronisingitwiththechangesfromthe
centralrepository
$gitpush<remote><branch>=>pushthespecifiedbranchto<remote>
$gitpush<remote>force=>forcethepushevenifitresultsinanonfastforwardmerge
$gitpush<remote>all=>pushallofyourlocalbranchestothespecifiedremote
$gitpush<remote>tags=>sendsallofyourlocaltagstotheremoterepository
$gitpushuorigin<featurebranch>=>pushbranchtothecentralrepository(origin),andaddsitasaremotetrackingbranch
$gitpush<remotename>delete<remotebranch>=>deletingremotebranches

You might also like