OpenSees Cloud
OpenSees AMI
How to Keep Your OpenSees Code Private on GitHub
Original Post - 16 May 2023 - Michael H. Scott
Visit Structural Analysis Is Simple on Substack.
I often mention the Concrete23 material model, but you won’t find it in the main OpenSees GitHub repository or in any of the repo’s public forks.
You won’t find Concrete23 because it doesn’t exist. Or maybe the model does exist but I keep it in a private fork of OpenSees. You’ll never know…
Let’s assume the latter is actually true and I have a private branch of the main OpenSees repository. How did I set that up?
Like any rational person, I first Googled how to maintain a private fork of a public repo. There were a few reasonable results and these instructions by Harry Roberts appeared to be the most reasonable and easy to follow. I then confirmed with Minjie that this is how to do it.
Here are the instructions adapted to OpenSees.
Create a Private Repo
Login to your GitHub account then go to
github.com/new
and create a private
repository.
You do not need to initialize this repository–leave it empty.
Set a Private Remote
A remote repository is the endpoint on github.com
where you will push
your code. You can see the remotes on your local machine by using the
git remote -v
command. If you followed
the instructions in this post,
you should have origin and upstream as remotes for fetch and push
operations.
The addresses show that origin points to your public fork of OpenSees, username/OpenSees.git, while upstream points to the main OpenSees repo, OpenSees/OpenSees.git.
Next, set a remote that points to the private repository. You can call the remote whatever you want–this example uses private.
git remote add private ssh://git@github.com:username/PrivateRepo.git
The remote address syntax may be slightly different on your machine,
e.g., git@github.com:username/OpenSees.git
. Mimic whatever syntax is
shown by git remote -v
when adding your private remote.
Do git remote -v
again and you will see the new private remote is
available for fetch
and push
.
Create a Private Development Branch
On your local machine, checkout a new branch on which you will develop Concrete23.
git checkout -b concrete23
Finally, tell your new branch to push to the private remote.
git push -u private concrete23
All pushes from the concrete23
branch will go to the private repository
to which private
points.
The first time you push will take a while as you’re pushing the entire OpenSees repo up to your private repo.
Push Code to Your Private Repo
As you hit important milestones in developing Concrete23 on the
concrete23
branch, you’ll want to push changes up to the private repo.
This is business as usual.
git add Concrete23.cpp
git commit -m "Updating smeared crack calculation"
git push
Having already set the upstream tracking of concrete23
with the -u
option, the commits will go to only the private repo.
Go to your private repo at github.com/username/PrivateRepo
and verify
the updates are there. Then go to your public OpenSees fork,
github.com/username/OpenSees
, and verify the updates are not there.
Merge Public OpenSees into Your Private Branch
Let’s say some new updates have been merged into the public OpenSees and you want to bring those updates into your private branch. I assume you bring upstream OpenSees changes into your master branch then merge those changes into multiple branches, one of which is the concrete23 branch dedicated to the private repo.
First, pull from upstream into your master branch (see these instructions).
git checkout master
git pull upstream master
After resolving any conflicts or other issues, checkout your concrete23
branch and merge.
git checkout concrete23
git merge master
Resolve any additional conflicts that arise. Now you can push the updates to the private repo.
git push
The upstream tracking of the concrete23
branch to the private repo was
already established with the -u
option.
Note that you have to perform this pull, merge, push process every time you want to merge public OpenSees into your private branch.
Merge Your Private Branch into Public OpenSees
Your journal article on the wonders of Concrete23 has been published and you are ready to share the model for the greater good of the OpenSees community.
Because you cannot push directly to the master branch of OpenSees, you will have to make a pull request.
First, change the upstream remote for your concrete23
branch to the
upstream OpenSees remote (use git remote -v
to verify the upstream
address).
git push -u upstream concrete23
Then go to github.com
and open a pull request.
Finally, wait for Frank to merge your pull request.
Remember, if you never merge your private branch into public OpenSees, then it’s like the code never existed–make a pull request.
Additional Considerations
To push to a private repo from multiple machines linked to your GitHub account, you will have to set the private remote on each machine. No big deal.
You can have more than one branch on your local machine point to the
private repo. Just be sure to set the upstream tracking with the -u
option of git push
, e.g., when you’re ready to tackle Steel08.
git checkout -b steel08
git push -u private steel08
You can create other branches to point to other private repos.
To collaborate with others on a private repo, give your collaborators access to the private repo. Your collaborators will have to set the private remote on their machines, but then it’s pretty much business as usual.