{"thread":{"id":"26196","subject":"Tracking branches and pulling on remote","startedAt":"2011-01-05T00:58:47Z","lastAt":"2011-01-05T16:44:16Z","messageCount":4,"participants":["Maaartin","Jeff King","Maaartin-1"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"158932","messageId":"loom.20110105T013525-413@post.gmane.org","threadId":"26196","inReplyTo":null,"subject":"Tracking branches and pulling on remote","fromName":"Maaartin","fromEmail":"grajcar1@seznam.cz","sentAt":"2011-01-05T00:58:47Z","receivedAt":"2011-01-05T00:58:47Z","isPatch":false,"sender":{"key":"grajcar1@seznam.cz","avatar":null},"body":"1.\nI'm using git for couple of months and still don't get it. In a new repo a have \ntwo branches: master and X. I pushed both to the server, everything seems to \nwork. However, there's origin/master but no origin/X in my repo. When I execute\ngit fetch --all -v\nonly master gets fetched. I've created an entry in the .git/config, no change. \nI've tried things like\ngit branch --track X origin/X\nand all of them ends with an error message. Finally I've found out that\ngit config --add remote.origin.fetch refs/heads/X:refs/remotes/origin/X\nseems to do it, was it right?\n\n2.\nI'd like to do some (at least for now) private changes on a foreign project. The \nideal way I think about would be the following:\n- my local repo is linked to my own server (for backup purposes and for private \ncooperation with a college)\n- the repo on my server is linked to the github hosting the project\nNow, I'd need to do something like\nssh myserver git fetch\nand everything would be fine. I can do it this way, but I'd prefer something like\ngit remote fetch\nor even\ngit fetch --remote-too\nwhich would first make my server fetch from its origin and then my local repo \nfetch from my server. Is there such a thing? Would you recommend me doing it in \na different way?\n"},{"id":"158941","messageId":"20110105050108.GA5884@sigill.intra.peff.net","threadId":"26196","inReplyTo":"loom.20110105T013525-413@post.gmane.org","subject":"Re: Tracking branches and pulling on remote","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-01-05T05:01:08Z","receivedAt":"2011-01-05T05:01:08Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Jan 05, 2011 at 12:58:47AM +0000, Maaartin wrote:\n\n> 1.\n> I'm using git for couple of months and still don't get it. In a new repo a have \n> two branches: master and X. I pushed both to the server, everything seems to \n> work. However, there's origin/master but no origin/X in my repo. When I execute\n> git fetch --all -v\n> only master gets fetched. I've created an entry in the .git/config, no change. \n> I've tried things like\n> git branch --track X origin/X\n> and all of them ends with an error message. Finally I've found out that\n> git config --add remote.origin.fetch refs/heads/X:refs/remotes/origin/X\n> seems to do it, was it right?\n\nThere should already have been a remote.origin.fetch that looked like:\n\n  $ git config remote.origin.fetch\n  +refs/heads/*:refs/remotes/origin/*\n\nwhich is a superset of what you added. If you run the git config command\nI did above, what do you see? If you have a wildcard line like the one\nabove (which is added during the initial clone), then the config you\nadded would have done nothing.\n\nAre you absolutely sure that the branch was pushed to the remote side in\nthe first place? How did you push it?\n\n> 2.\n> I'd like to do some (at least for now) private changes on a foreign project. The \n> ideal way I think about would be the following:\n> - my local repo is linked to my own server (for backup purposes and for private \n> cooperation with a college)\n> - the repo on my server is linked to the github hosting the project\n> Now, I'd need to do something like\n> ssh myserver git fetch\n> and everything would be fine. I can do it this way, but I'd prefer something like\n> git remote fetch\n> or even\n> git fetch --remote-too\n> which would first make my server fetch from its origin and then my local repo \n> fetch from my server. Is there such a thing? Would you recommend me doing it in \n> a different way?\n\nThere isn't really a shortcut for the two-level thing you're trying to\ndo. But consider rearranging your topology to always pull to the local\nrepo, and then push changes up to your backup/collaboration server.\n\nSomething like:\n\n  $ git clone http://github.com/whatever/project.git\n  $ cd project\n  $ git remote add myserver myserver:/path/to/backup repo\n\nand then your workflow is:\n\n  : hmm, I feel like working on project. what happened upstream?\n  $ git pull ;# or git fetch origin; gitk origin... ; git merge origin\n  $ hack hack hack\n  : ok, now I have some work to show to my collaborator\n  $ git push myserver\n\nor possibly:\n\n  : ok, now what has my collaborator been up to\n  $ git fetch myserver\n  $ gitk myserver/topic\n  : I like it, let's merge\n  $ git merge myserver/topic\n  : Now push back my merge\n  $ git push myserver\n\nYou might also find it convenient to swap which remote is \"origin\"\n(since it is the default for \"git push\" without arguments). That is, you\nprimarily consider your local repo to be a clone of what's on\n\"myserver\", but you occasionally fetch and merge changes from upstream,\nlike:\n\n  : ok, what has my collaborator been working on?\n  $ git pull\n  : and what has upstream been up to?\n  $ git fetch upstream\n  : oh, neat stuff. let's merge it\n  $ git merge upstream\n  : and then let's publish it so our collaborator will also work on top\n  : of it\n  $ git push ;# implicitly to origin\n\nHow you want to set it up really depends on which mental model\nrepresents your workflow best.\n\n-Peff\n"},{"id":"158969","messageId":"4D249EFA.5050408@seznam.cz","threadId":"26196","inReplyTo":"20110105050108.GA5884@sigill.intra.peff.net","subject":"Re: Tracking branches and pulling on remote","fromName":"Maaartin-1","fromEmail":"grajcar1@seznam.cz","sentAt":"2011-01-05T16:40:26Z","receivedAt":"2011-01-05T16:40:26Z","isPatch":false,"sender":{"key":"grajcar1@seznam.cz","avatar":null},"body":"On 11-01-05 06:01, Jeff King wrote:\n> On Wed, Jan 05, 2011 at 12:58:47AM +0000, Maaartin wrote:\n> \n>> 1.\n>> I'm using git for couple of months and still don't get it. In a new repo a have \n>> two branches: master and X. I pushed both to the server, everything seems to \n>> work. However, there's origin/master but no origin/X in my repo. When I execute\n>> git fetch --all -v\n>> only master gets fetched. I've created an entry in the .git/config, no change. \n>> I've tried things like\n>> git branch --track X origin/X\n>> and all of them ends with an error message. Finally I've found out that\n>> git config --add remote.origin.fetch refs/heads/X:refs/remotes/origin/X\n>> seems to do it, was it right?\n> \n> There should already have been a remote.origin.fetch that looked like:\n> \n>   $ git config remote.origin.fetch\n>   +refs/heads/*:refs/remotes/origin/*\n> \n> which is a superset of what you added. If you run the git config command\n> I did above, what do you see?\n\nNo, there had been just the single line\n\nrefs/heads/master:refs/remotes/origin/master\n\nand after my change I got\n\nrefs/heads/X:refs/remotes/origin/X\nerror: More than one value for the key remote.origin.fetch:\nrefs/heads/master:refs/remotes/origin/master\n\nIt was probably my fault, I may have copied a config file from elsewhere\n(and adapted the URL).\n\n> If you have a wildcard line like the one\n> above (which is added during the initial clone), then the config you\n> added would have done nothing.\n\nI see.\n\n> Are you absolutely sure that the branch was pushed to the remote side in\n> the first place? How did you push it?\n\nYes, I'm sure. I don't remember how I did it, probably using\ngit push origin master\n\nI think it's clear now.\n\n>> 2.\n>> I'd like to do some (at least for now) private changes on a foreign project. The \n>> ideal way I think about would be the following:\n>> - my local repo is linked to my own server (for backup purposes and for private \n>> cooperation with a college)\n>> - the repo on my server is linked to the github hosting the project\n>> Now, I'd need to do something like\n>> ssh myserver git fetch\n>> and everything would be fine. I can do it this way, but I'd prefer something like\n>> git remote fetch\n>> or even\n>> git fetch --remote-too\n>> which would first make my server fetch from its origin and then my local repo \n>> fetch from my server. Is there such a thing? Would you recommend me doing it in \n>> a different way?\n> \n> There isn't really a shortcut for the two-level thing you're trying to\n> do. But consider rearranging your topology to always pull to the local\n> repo, and then push changes up to your backup/collaboration server.\n> \n> Something like:\n> \n>   $ git clone http://github.com/whatever/project.git\n>   $ cd project\n>   $ git remote add myserver myserver:/path/to/backup repo\n> \n> and then your workflow is:\n> \n>   : hmm, I feel like working on project. what happened upstream?\n>   $ git pull ;# or git fetch origin; gitk origin... ; git merge origin\n>   $ hack hack hack\n>   : ok, now I have some work to show to my collaborator\n>   $ git push myserver\n> \n> or possibly:\n> \n>   : ok, now what has my collaborator been up to\n>   $ git fetch myserver\n>   $ gitk myserver/topic\n>   : I like it, let's merge\n>   $ git merge myserver/topic\n>   : Now push back my merge\n>   $ git push myserver\n> \n> You might also find it convenient to swap which remote is \"origin\"\n> (since it is the default for \"git push\" without arguments). That is, you\n> primarily consider your local repo to be a clone of what's on\n> \"myserver\", but you occasionally fetch and merge changes from upstream,\n> like:\n> \n>   : ok, what has my collaborator been working on?\n>   $ git pull\n>   : and what has upstream been up to?\n>   $ git fetch upstream\n>   : oh, neat stuff. let's merge it\n>   $ git merge upstream\n>   : and then let's publish it so our collaborator will also work on top\n>   : of it\n>   $ git push ;# implicitly to origin\n> \n> How you want to set it up really depends on which mental model\n> represents your workflow best.\n\nOK, I swapped origin and upstream and made aliases\n\tfetchboth = !\"git fetch; git fetch upstream\"\n\tfetup = fetch upstream\nwhich is about everything I need for now.\n\nThanks, Maaartin.\n"},{"id":"158968","messageId":"20110105164416.GA4393@sigill.intra.peff.net","threadId":"26196","inReplyTo":"4D249EFA.5050408@seznam.cz","subject":"Re: Tracking branches and pulling on remote","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2011-01-05T16:44:16Z","receivedAt":"2011-01-05T16:44:16Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Jan 05, 2011 at 05:40:26PM +0100, Maaartin-1 wrote:\n\n> >   $ git config remote.origin.fetch\n> >   +refs/heads/*:refs/remotes/origin/*\n> > \n> > which is a superset of what you added. If you run the git config command\n> > I did above, what do you see?\n> \n> No, there had been just the single line\n> \n> refs/heads/master:refs/remotes/origin/master\n\nAh, OK, then that is the culprit. And the config line you added was a\nreasonable solution (though you may consider simply switching it to a\nwildcard to cover any future branches, too).\n\n> OK, I swapped origin and upstream and made aliases\n> \tfetchboth = !\"git fetch; git fetch upstream\"\n> \tfetup = fetch upstream\n> which is about everything I need for now.\n\nCool. You can also use \"git fetch --all\" to do the equivalent of your\nfetchboth.\n\n-Peff\n"}]}