github - Trying to understand git upstream branch -
i have git project. remote have master branch, @ local have master , proj-structure branch. created proj-structure branch using 'git branch -b proj-structure'. @ proj-structure branch @ local, when try git push, git suggests me use git push --set-upstream origin proj-structure. read articles, should use git push --set-upstream master proj-structure. what's difference of master , origin when set upstream? if did use above command, remote create exact branch named proj-structure, , branch have commits local branch have, right?
you mixing 2 different concepts of git here. remote , branch.
remote [default: origin]
think of remote computer or person. specifying origin tell git who send current set of changes to.
branch [default: master]
you use branches keep track of separate lines of development. example can use master keep version of software tested , stable , add more branches try out new things.
think of them making copy modify.
and keeps copies separately.
now of course boring if had work on our new developments alone.
that's why don't want keep these branches on our own computer, share of them others.
usually have 1 central server used exchange (for example github). server remote named origin. pushing syncs the branch on server changes on the branch on computer , pulling syncs computer changes on server.
now, have made change know stable, on master branch on computer. can directly push master branch on our server (origin/master).
why? because git knows origin right remote push changes on branch , knows master branch called master on remote.
now lets make cool new experiment, adds pink rabbit software. because don't know yet if boss thinks idea, i'll keep in separate version now. make new branch called pink_rabbit.
i can't type git push, because our server doesn't have copy yet. because branch newly created, there no info send to.
now type:
git push --set-upstream origin pink_rabbit
what is: tell git, origin remote 1 push branch , put changes in branch called pink_rabbit on remote. next time git have information saved in branches upstream , git push work directly.
of course have typed master here, syncing experimental version on local machine directly main copy on server. kind of defeats purpose of branching in first place.
so why have these upstream links @ all?
lets company had policy, has prefix branches on server name.
on local machine, working own branches. is:
branch -b pink_rabbit git push --set-upstream origin tim/pink_rabbit this allow me work on pink_rabbit locally , publish server tim/pink_rabbit.
apart advanced usages, should name branches same (or @ least very, similar) named on server.
Comments
Post a Comment