cascade creek environment fern

GitHub-fu from master to main and handling upstream quickly

0

Now that GitHub has made the transition from master (good-bye slavery!), all existing repos need to change otherwise you will never remember if you should git checkout master or main. Fortunately the steps are pretty easy:

  1. Rename your local branch from master to main with git branch -m master main where I think -m means modify the name of the branch
  2. Now you just have to push that branch up so you have an origin/main with git push -u origin main
  3. And get rid of that master branch with git push --delete master
  4. Now go to Github.com and to https://github.com/your_org/your_repo and click on the Settings/Branches and change the default to main.

Dealing with friendly upstreams quickly

Well we have a scheme where there is a central shared bin repo for all our projects. This means we have a lot of places that have upstream connections. So that when a bug is found everyone gets it. Rather than doing Pull Requests and things, there are times when you quickly need to be able to update things and you know you are in control of the software and there are no others. In that case, this is a sequence that is fast and works well. It still has protection in that GitHub will refuse pushes that conflict of course, so it is not as dangerous as it looks:

# Create a submodule using https://github.com/_parent_/lib as an example
cd _your_repo_
# Assumes that you have the GitHub gh utilities
gh repo fork https://github.com/_parent_/lib lib --remote --clone=false
# we are not going to clone but make a submodule
git submodule add https://github.com/_your_org_/lib

This is pretty neat, you now have a lib repo which is forked from the central spot at the organization _parent_ and upstream is now set. So let’s make a change and then propagate it to origin/main, upstream/main and upstream/_branch_

# I like to check out branches that remind me where I am
cd lib
# So I usually use the first initial of the _your_org_ in the name and then my user name
git checkout -b rich-nlib
# make some change
git push -u main rich-nlib
# now rebase against local master and then push both
git fetch -p
# Now make sure that origin/main is fresh against upstream/main
git fetch upstream
git checkout -b upstream-main upstream/main
git checkout main
git pull --ff-only
git rebase upstream-main
git rebase upstream-main -i
# Now we have origin/main synced to upstream
git checkout rich-nlib
git rebase main
git rebase main -i
# Now we have the right branch and it is squashed against main
git push -f
# So here is the big one, push to origin/master
git push origin rich-nlib:main
# Now you want to update the upstream
git push upstream rich-nlib:main

The cool thing about this is that once all this is setup and if you know you are the only one working on things, then many times you can just do:

# if you know all is up to date
git push origin rich-nlib:main
git push upstream rich-nlib:main

Related Posts

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© All Right Reserved