Syncing upstream branches in my fork

My apologies, my Google/GitHub-fu has failed me, so I resort to asking this community for help (an uncommon, perhaps first-time, experience). I worry that I’m doing this all wrong. Please steer me right if I am.

I forked the Python main repo awhile ago (couple years maybe?), before the 3.7 branch was created. 3.7 is now in beta, so the 3.7 branch was created. The two repos in question are:

I followed the instructions here to keep the latter in sync with the former:

but it still lacks a 3.7 branch, both on the web and locally. I captured those instructions in a trivial shell script:

git fetch upstream
git co master
git merge upstream/master
echo "now push when ready"

Here’s a trimmed example of git br -a:

% git br -a
* master
  ... others, but no 3.7 ...

How do I create a remotes/origin/3.7 branch which will track remotes/upstream/3.7? Is there some combinations of shell level git commands which will accomplish this, or do I need to manually edit .git/config? This will be an ongoing problem as new 3.x releases of Python approach. It would be great if I could automatically create new 3.x branches in remotes/origin as they appear in remotes/upstream…


If you have not made any modifications to the code, the easiest way to sync everything up is to delete your fork and fork again. It is not elegant but takes a couple of seconds.

If this is not your case you can fork the branch that you need and integrate it in your current code, or make a branch with the same name and follow the process described in the link you posted for that particular branch. but as a lazy busy man, I recommend you the first option.


Thanks. If it comes to that, I suppose I could do that. I do use the fork to produce pull requests, so it has had some activity. There has to be some way to drag the branch info out of upstream.

Yes, there is (I believe this is a common task) . I usually manage git repositories through my IDE’s integrated git system. In NetBeans for example, this operation is just marking up a check box for the new branch you want to fetch.
However I am not sure about how to do that in the command line. I am not very skillful with that.
Let me check the documentation and if I find it out I will let you know.

I got this from one of my python-dev peeps:

git checkout -b 3.7 upstream/3.7
git push -u origin 3.7

which worked, though 3.7 wasn’t updating. I think this little shell script does the right thing, however:


# From this github help page:

BR=$(git br | egrep '^[*]' | awk '{print $2}')
trap "git co $BR" EXIT

for branch in master 3.7 ; do
    git co $branch
    git fetch upstream
    git merge upstream/$branch
    read -p "Do you wish to install this program (y/n)?" yn
    if ["x$yn" = "xy"] ; then
	git push
	echo "Switch bach to $branch and push when ready."

Great! I’ll test it when I get home.
Thanks man!

My Github App solves part of the problem : )  It syncs master branch automatically but currently does not automatcailly tag commits.

:robot: a GitHub App built with probot that keeps your repository up-to-date with upstream changes via automated PRs.

1 Like