git - Automatically update upstream branches -
i have repository (origin
) has been forked (in github terms) repository (upstream
). development in topic branches , never touch branches nowadays in upstream repository (master
, developement
, 1.x
, etc.).
this illustration of branches in repository
$ git branch -a # plus hand annotations development [upstream-maintained: should == upstream/master] feature-1 [mine: should track origin/feature-1] feature-2 [mine: should track origin/feature-2] * master [upstream-maintained: should == upstream/master] remotes/origin/head -> origin/master remotes/origin/development remotes/origin/feature-1 remotes/origin/feature-2 remotes/origin/master remotes/upstream/development remotes/upstream/gh-pages [i not care this..] remotes/upstream/master remotes/upstream/stable-1.x [...nor care these two..] remotes/upstream/stable-2.x [...stable-* branches]
after fetch upstream repository, have go through tedious task of updating upstream-maintained branches: switch master
, merge --ff-only upstream/master
, force origin. must repeated every upstream-maintained branch care about. please note merge --ff-only
works because never touch branches.
i git pull
these tedious updates me.
is there way teach git upstream-maintained branches should pushed origin
pulled , tracked upstream
?
as mentioned in "how can pull 1 remote , force git?", can:
make sure force origin:
git config remote.pushdefault origin git config push.default matching
setup upstream branch:
git fetch upstream git branch -u upstream/master foo
note should rebase topic
branches on top of upstream/master
(not merge), in order not have merge commits in pull requests. means git force -f
updating fork remote branch (that update pull request automatically)
you can forcefulness rebase either through:
git config autosetuprebase remote # or git branch.foo.rebase true
for example:
c:\users\vonc\prog\git\so>git clone https://github.com/gioele/offlineimap.git cloning 'offlineimap'... remote: counting objects: 9445, done. remote: compressing objects: 100% (3701/3701), done. remote: total 9445 (delta 4962), reused 9445 (delta 4962) receiving objects: 100% (9445/9445), 5.75 mib | 2.18 mib/s, done. resolving deltas: 100% (4962/4962), done. checking connectivity... done. c:\users\vonc\prog\git\so>cd offlineimap c:\users\vonc\prog\git\so\offlineimap>git remote add together upstream https://github.com/offlineimap/offlineimap.git
lets see master refers now:
c:\users\vonc\prog\git\so\offlineimap>git branch -avvv * master 1746676 [origin/master] create idle mode work 1 time again remotes/origin/head -> origin/master c:\users\vonc\prog\git\so\offlineimap>git config --local -l remote.origin.url=https://github.com/gioele/offlineimap.git remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* branch.master.remote=origin branch.master.merge=refs/heads/master remote.upstream.url=https://github.com/offlineimap/offlineimap.git remote.upstream.fetch=+refs/heads/*:refs/remotes/upstream/*
let's create origin destination push:
c:\users\vonc\prog\git\so\offlineimap>git config push.default matching c:\users\vonc\prog\git\so\offlineimap>git config remote.pushdefault origin
let's alter upstream branch:
c:\users\vonc\prog\git\so\offlineimap>git fetch upstream remote: counting objects: 55, done. remote: compressing objects: 100% (55/55), done. remote: total 55 (delta 25), reused 1 (delta 0) unpacking objects: 100% (55/55), done. https://github.com/offlineimap/offlineimap * [new branch] master -> upstream/master c:\users\vonc\prog\git\so\offlineimap>git branch -u upstream/master master branch master set track remote branch master upstream.
the master
branch set monitoring upstream/master
:
c:\users\vonc\prog\git\so\offlineimap>git br -avvv * master 1746676 [upstream/master: behind 10] create idle mode work 1 time again
now git pull
(or better, git pull --rebase
) pull upstream
:
c:\users\vonc\prog\git\so\offlineimap>git pull --rebase first, rewinding head replay work on top of it... fast-forwarded master 6bd76fed5a7e1e24310517b3510c465929870c08.
(and 6bd76fed5a7e1e24310517b3510c465929870c08
upstream/master
commit)
a git push
still force origin:
c:\users\vonc\prog\git\so\offlineimap>git force remote: permission gioele/offlineimap.git denied vonc. fatal: unable access 'https://github.com/gioele/offlineimap.git/': requested url returned error: 403
(normal, since not gioele
, don't have write access repo)
git
No comments:
Post a Comment