Академический Документы
Профессиональный Документы
Культура Документы
localbranchingonthecheap
Searchentiresite...
About
Documentation
Reference
Book
Videos
ExternalLinks
Blog
Downloads
GUIClients
Logos
Community
DownloadthisbookinPDF,mobi,orePubformforfree.
ThisbookistranslatedintoDeutsch, ,,Franais,,Nederlands,,,
Portugus(Brasil)andetina.
PartialtranslationsavailableinArabic,Espaol,Indonesian,Italiano,Suomi,,Polskiand
Trke.
TranslationsstartedforAzrbaycandili,,Catal,Esperanto,Espaol(Nicaragua),, ,
Magyar,NorwegianBokml,Romn,,,TingVit,and.
ThesourceofthisbookishostedonGitHub.
Patches,suggestionsandcommentsarewelcome.
RelatedMaterial
gitremoteinReference
gitpullinReference
gitpushinReference
gitfetchinReference
gitcloneinReference
Chapters
1.1.GettingStarted
1.1.1AboutVersionControl
2.1.2AShortHistoryofGit
3.1.3GitBasics
4.1.4TheCommandLine
5.1.5InstallingGit
6.1.6FirstTimeGitSetup
7.1.7GettingHelp
8.1.8Summary
2.2.GitBasics
https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes 1/7
24/06/2016 Git - Working with Remotes
1.2.1GettingaGitRepository
2.2.2RecordingChangestotheRepository
3.2.3ViewingtheCommitHistory
4.2.4UndoingThings
5.2.5WorkingwithRemotes
6.2.6Tagging
7.2.7GitAliases
8.2.8Summary
3.3.GitBranching
1.3.1BranchesinaNutshell
2.3.2BasicBranchingandMerging
3.3.3BranchManagement
4.3.4BranchingWorkflows
5.3.5RemoteBranches
6.3.6Rebasing
7.3.7Summary
4.4.GitontheServer
1.4.1TheProtocols
2.4.2GettingGitonaServer
3.4.3GeneratingYourSSHPublicKey
4.4.4SettingUptheServer
5.4.5GitDaemon
6.4.6SmartHTTP
7.4.7GitWeb
8.4.8GitLab
9.4.9ThirdPartyHostedOptions
10.4.10Summary
5.5.DistributedGit
1.5.1DistributedWorkflows
2.5.2ContributingtoaProject
3.5.3MaintainingaProject
4.5.4Summary
1.6.GitHub
1.6.1AccountSetupandConfiguration
2.6.2ContributingtoaProject
3.6.3MaintainingaProject
4.6.4Managinganorganization
5.6.5ScriptingGitHub
6.6.6Summary
2.7.GitTools
1.7.1RevisionSelection
2.7.2InteractiveStaging
3.7.3StashingandCleaning
4.7.4SigningYourWork
https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes 2/7
24/06/2016 Git - Working with Remotes
5.7.5Searching
6.7.6RewritingHistory
7.7.7ResetDemystified
8.7.8AdvancedMerging
9.7.9Rerere
10.7.10DebuggingwithGit
11.7.11Submodules
12.7.12Bundling
13.7.13Replace
14.7.14CredentialStorage
15.7.15Summary
3.8.CustomizingGit
1.8.1GitConfiguration
2.8.2GitAttributes
3.8.3GitHooks
4.8.4AnExampleGitEnforcedPolicy
5.8.5Summary
4.9.GitandOtherSystems
1.9.1GitasaClient
2.9.2MigratingtoGit
3.9.3Summary
5.10.GitInternals
1.10.1PlumbingandPorcelain
2.10.2GitObjects
3.10.3GitReferences
4.10.4Packfiles
5.10.5TheRefspec
6.10.6TransferProtocols
7.10.7MaintenanceandDataRecovery
8.10.8EnvironmentVariables
9.10.9Summary
1.A1.GitinOtherEnvironments
1.A1.1GraphicalInterfaces
2.A1.2GitinVisualStudio
3.A1.3GitinEclipse
4.A1.4GitinBash
5.A1.5GitinZsh
6.A1.6GitinPowershell
7.A1.7Summary
2.A2.EmbeddingGitinyourApplications
1.A2.1CommandlineGit
2.A2.2Libgit2
3.A2.3JGit
https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes 3/7
24/06/2016 Git - Working with Remotes
3.A3.GitCommands
1.A3.1SetupandConfig
2.A3.2GettingandCreatingProjects
3.A3.3BasicSnapshotting
4.A3.4BranchingandMerging
5.A3.5SharingandUpdatingProjects
6.A3.6InspectionandComparison
7.A3.7Debugging
8.A3.8Patching
9.A3.9Email
10.A3.10ExternalSystems
11.A3.11Administration
12.A3.12PlumbingCommands
2ndEdition
2.5GitBasicsWorkingwithRemotes
WorkingwithRemotes
TobeabletocollaborateonanyGitproject,youneedtoknowhowtomanageyourremoterepositories.
RemoterepositoriesareversionsofyourprojectthatarehostedontheInternetornetworksomewhere.You
canhaveseveralofthem,eachofwhichgenerallyiseitherreadonlyorread/writeforyou.Collaborating
withothersinvolvesmanagingtheseremoterepositoriesandpushingandpullingdatatoandfromthem
whenyouneedtosharework.Managingremoterepositoriesincludesknowinghowtoaddremote
repositories,removeremotesthatarenolongervalid,managevariousremotebranchesanddefinethemas
beingtrackedornot,andmore.Inthissection,wellcoversomeoftheseremotemanagementskills.
ShowingYourRemotes
Toseewhichremoteserversyouhaveconfigured,youcanrunthegit remotecommand.Itliststhe
shortnamesofeachremotehandleyouvespecified.Ifyouveclonedyourrepository,youshouldatleastsee
originthatisthedefaultnameGitgivestotheserveryouclonedfrom:
$ git clone https://github.com/schacon/ticgit
Cloning into 'ticgit'...
remote: Reusing existing pack: 1857, done.
remote: Total 1857 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (1857/1857), 374.35 KiB | 268.00 KiB/s, done.
Resolving deltas: 100% (772/772), done.
Checking connectivity... done.
$ cd ticgit
$ git remote
origin
Youcanalsospecify-v,whichshowsyoutheURLsthatGithasstoredfortheshortnametobeusedwhen
readingandwritingtothatremote:
$ git remote -v
origin https://github.com/schacon/ticgit (fetch)
origin https://github.com/schacon/ticgit (push)
Ifyouhavemorethanoneremote,thecommandliststhemall.Forexample,arepositorywithmultiple
remotesforworkingwithseveralcollaboratorsmightlooksomethinglikethis.
$ cd grit
$ git remote -v
https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes 4/7
24/06/2016 Git - Working with Remotes
bakkdoor https://github.com/bakkdoor/grit (fetch)
bakkdoor https://github.com/bakkdoor/grit (push)
cho45 https://github.com/cho45/grit (fetch)
cho45 https://github.com/cho45/grit (push)
defunkt https://github.com/defunkt/grit (fetch)
defunkt https://github.com/defunkt/grit (push)
koke git://github.com/koke/grit.git (fetch)
koke git://github.com/koke/grit.git (push)
origin git@github.com:mojombo/grit.git (fetch)
origin git@github.com:mojombo/grit.git (push)
Thismeanswecanpullcontributionsfromanyoftheseusersprettyeasily.Wemayadditionallyhave
permissiontopushtooneormoreofthese,thoughwecanttellthathere.
NoticethattheseremotesuseavarietyofprotocolswellcovermoreaboutthisinGettingGitonaServer.
AddingRemoteRepositories
Wevementionedandgivensomedemonstrationsofhowtheclonecommandimplicitlyaddstheorigin
remoteforyou.Hereshowtoaddanewremoteexplicitly.ToaddanewremoteGitrepositoryasa
shortnameyoucanreferenceeasily,rungit remote add <shortname> <url>:
$ git remote
origin
$ git remote add pb https://github.com/paulboone/ticgit
$ git remote -v
origin https://github.com/schacon/ticgit (fetch)
origin https://github.com/schacon/ticgit (push)
pb https://github.com/paulboone/ticgit (fetch)
pb https://github.com/paulboone/ticgit (push)
NowyoucanusethestringpbonthecommandlineinlieuofthewholeURL.Forexample,ifyouwantto
fetchalltheinformationthatPaulhasbutthatyoudontyethaveinyourrepository,youcanrungit fetch
pb:
$ git fetch pb
remote: Counting objects: 43, done.
remote: Compressing objects: 100% (36/36), done.
remote: Total 43 (delta 10), reused 31 (delta 5)
Unpacking objects: 100% (43/43), done.
From https://github.com/paulboone/ticgit
* [new branch] master -> pb/master
* [new branch] ticgit -> pb/ticgit
Paulsmasterbranchisnowaccessiblelocallyaspb/masteryoucanmergeitintooneofyourbranches,or
youcancheckoutalocalbranchatthatpointifyouwanttoinspectit.(Wellgooverwhatbranchesareand
howtousetheminmuchmoredetailinGitBranching.)
FetchingandPullingfromYourRemotes
Asyoujustsaw,togetdatafromyourremoteprojects,youcanrun:
$ git fetch [remote-name]
Thecommandgoesouttothatremoteprojectandpullsdownallthedatafromthatremoteprojectthatyou
donthaveyet.Afteryoudothis,youshouldhavereferencestoallthebranchesfromthatremote,whichyou
canmergeinorinspectatanytime.
Ifyouclonearepository,thecommandautomaticallyaddsthatremoterepositoryunderthenameorigin.
So,git fetch originfetchesanynewworkthathasbeenpushedtothatserversinceyoucloned(orlast
fetchedfrom)it.Itsimportanttonotethatthegit fetchcommandonlydownloadsthedatatoyourlocal
repositoryitdoesntautomaticallymergeitwithanyofyourworkormodifywhatyourecurrently
https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes 5/7
24/06/2016 Git - Working with Remotes
workingon.Youhavetomergeitmanuallyintoyourworkwhenyoureready.
Ifyourcurrentbranchissetuptotrackaremotebranch(seethenextsectionandGitBranchingformore
information),youcanusethegit pullcommandtoautomaticallyfetchandthenmergethatremotebranch
intoyourcurrentbranch.Thismaybeaneasierormorecomfortableworkflowforyouandbydefault,the
git clonecommandautomaticallysetsupyourlocalmasterbranchtotracktheremotemasterbranch(or
whateverthedefaultbranchiscalled)ontheserveryouclonedfrom.Runninggit pullgenerallyfetches
datafromtheserveryouoriginallyclonedfromandautomaticallytriestomergeitintothecodeyoure
currentlyworkingon.
PushingtoYourRemotes
Whenyouhaveyourprojectatapointthatyouwanttoshare,youhavetopushitupstream.Thecommand
forthisissimple:git push [remote-name] [branch-name].Ifyouwanttopushyourmasterbranchto
youroriginserver(again,cloninggenerallysetsupbothofthosenamesforyouautomatically),thenyou
canrunthistopushanycommitsyouvedonebackuptotheserver:
$ git push origin master
Thiscommandworksonlyifyouclonedfromaservertowhichyouhavewriteaccessandifnobodyhas
pushedinthemeantime.Ifyouandsomeoneelsecloneatthesametimeandtheypushupstreamandthen
youpushupstream,yourpushwillrightlyberejected.Youllhavetofetchtheirworkfirstandincorporateit
intoyoursbeforeyoullbeallowedtopush.SeeGitBranchingformoredetailedinformationonhowtopush
toremoteservers.
InspectingaRemote
ItliststheURLfortheremoterepositoryaswellasthetrackingbranchinformation.Thecommandhelpfully
tellsyouthatifyoureonthemasterbranchandyourungit pull,itwillautomaticallymergeinthemaster
branchontheremoteafteritfetchesalltheremotereferences.Italsolistsalltheremotereferencesithas
pulleddown.
Thatisasimpleexampleyourelikelytoencounter.WhenyoureusingGitmoreheavily,however,youmay
seemuchmoreinformationfromgit remote show:
$ git remote show origin
* remote origin
URL: https://github.com/my-org/complex-project
Fetch URL: https://github.com/my-org/complex-project
Push URL: https://github.com/my-org/complex-project
HEAD branch: master
Remote branches:
master tracked
dev-branch tracked
markdown-strip tracked
https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes 6/7
24/06/2016 Git - Working with Remotes
Thiscommandshowswhichbranchisautomaticallypushedtowhenyourungit pushwhileoncertain
branches.Italsoshowsyouwhichremotebranchesontheserveryoudontyethave,whichremotebranches
youhavethathavebeenremovedfromtheserver,andmultiplelocalbranchesthatareabletomerge
automaticallywiththeirremotetrackingbranchwhenyourungit pull.
RemovingandRenamingRemotes
Youcanrungit remote renametochangearemotesshortname.Forinstance,ifyouwanttorenamepbto
paul,youcandosowithgit remote rename:
Itsworthmentioningthatthischangesallyourremotetrackingbranchnames,too.Whatusedtobe
referencedatpb/masterisnowatpaul/master.
Ifyouwanttoremovearemoteforsomereasonyouvemovedtheserverorarenolongerusinga
particularmirror,orperhapsacontributorisntcontributinganymoreyoucanusegit remote rm:
$ git remote rm paul
$ git remote
origin
prev|next
ThisopensourcedsiteishostedonGitHub.
Patches,suggestionsandcommentsarewelcome.
GitisamemberofSoftwareFreedomConservancy
https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes 7/7