{"thread":{"id":"35855","subject":"Process of updating a local branch from another with tracking","startedAt":"2014-02-12T21:55:01Z","lastAt":"2014-02-13T08:42:04Z","messageCount":2,"participants":["Robert Dailey","Chris Packham"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"234694","messageId":"CAHd499CQK7Mmd+vWb74Nj4usX8KhmurJNd31MrAMUs6Vb2zOOw@mail.gmail.com","threadId":"35855","inReplyTo":null,"subject":"Process of updating a local branch from another with tracking","fromName":"Robert Dailey","fromEmail":"rcdailey.lists@gmail.com","sentAt":"2014-02-12T21:55:01Z","receivedAt":"2014-02-12T21:55:01Z","isPatch":false,"sender":{"key":"rcdailey.lists@gmail.com","avatar":null},"body":"I have the following alias defined:\nsync = \"!f() { cbr=$(git rev-parse --abbrev-ref HEAD); git co $1 &&\ngit pull && git co $cbr && git rebase $1; }; f\"\n\nThe goal is to basically update a local branch which tracks a branch\non a remote, and then rebase my local topic branch onto that updated\nlocal branch.\n\nI do this instead of just rebasing onto origin/master. Example:\n\ngit checkout master\ngit pull --rebase origin master\ngit checkout topic1\ngit rebase master\n\nI could do this instead but not sure if it is recommended:\n\ngit checkout topic1\ngit fetch\ngit rebase origin/master\n\nAny thoughts on the alias I created? I'm a Windows user and still new\nto linux stuff, so if it sucks or could be simplified just let me\nknow.\n\nAnd as a secondary question, just curious what people think about\nrebasing onto a remote tracking branch. When I do merges I usually\nrefer to the remote branch, but during rebase I use the local branch\ninstead, but I don't know if there is any functional reason to not\nskip the local branch and go straight to the remote tracking branch\n(it saves a step).\n"},{"id":"234717","messageId":"52FC855C.9010204@gmail.com","threadId":"35855","inReplyTo":"CAHd499CQK7Mmd+vWb74Nj4usX8KhmurJNd31MrAMUs6Vb2zOOw@mail.gmail.com","subject":"Re: Process of updating a local branch from another with tracking","fromName":"Chris Packham","fromEmail":"judge.packham@gmail.com","sentAt":"2014-02-13T08:42:04Z","receivedAt":"2014-02-13T08:42:04Z","isPatch":false,"sender":{"key":"judge.packham@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155667?v=4"},"body":"On 13/02/14 10:55, Robert Dailey wrote:\n> I have the following alias defined:\n> sync = \"!f() { cbr=$(git rev-parse --abbrev-ref HEAD); git co $1 &&\n> git pull && git co $cbr && git rebase $1; }; f\"\n> \n> The goal is to basically update a local branch which tracks a branch\n> on a remote, and then rebase my local topic branch onto that updated\n> local branch.\n\nGenerally speaking there is little benefit in manually keeping a local\nbranch that just tracks a remote one because you already have a \"remote\ntracking branch\" which gets updated whenever you fetch from that remote.\nSo you could be doing something like\n\n  git fetch origin # or whatever other remotes you may have configured\n  git rebase origin/master # or whatever branch you're tracking\n\nYou can also tell git this kind of information when you create your\ntopic branch and git will to this all for you.\n\n  git checkout -b topic1 origin/master\n  git pull -r # -r makes pull run fetch + rebase instead of pull + merge\n\nIf you already have a topic branch and you want to tell it what remote\nbranch (upstream) to track you can do that too.\n\n  git checkout topic\n  git branch -u origin/master\n  git pull -r\n\n> I do this instead of just rebasing onto origin/master. Example:\n> \n> git checkout master\n> git pull --rebase origin master\n> git checkout topic1\n> git rebase master\n> \n> I could do this instead but not sure if it is recommended:\n> \n> git checkout topic1\n> git fetch\n> git rebase origin/master\n\nI do it all the time. Actually I set the upstream and I can just use\n'git pull -r'.\n\n> Any thoughts on the alias I created? I'm a Windows user and still new\n> to linux stuff, so if it sucks or could be simplified just let me\n> know.\n\nAliases are fine to save yourself some typing. In this case I think you\ncan just set the upstream branch and use 'git pull -r'. There is a\nconfig option to make this the default but you probably want to be\ncomfortable with the difference between merging and rebasing before you\nset that.\n\n> And as a secondary question, just curious what people think about\n> rebasing onto a remote tracking branch. When I do merges I usually\n> refer to the remote branch, but during rebase I use the local branch\n> instead, but I don't know if there is any functional reason to not\n> skip the local branch and go straight to the remote tracking branch\n> (it saves a step).\n\nBranches are branches. You might use multiple local branches to separate\ndependent topics that you're working on. You might do the same with\nremote branches if you have topics based on other peoples work.\n"}]}