Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save amir-saniyan/a3c76b7e545e3d84f82f27e6c6579245 to your computer and use it in GitHub Desktop.
Save amir-saniyan/a3c76b7e545e3d84f82f27e6c6579245 to your computer and use it in GitHub Desktop.
Create private branch of a public repository

Create private branch of a public repository

This gist describes how to create private branch (downstream) of a public repository (upstream).

Initialize repository

$ git init private-repo
$ cd private-repo

Add remotes

$ git remote add upstream git@github.com:<username>/public-repo.git
$ git remote add origin git@github.com:<username>/private-repo.git
$ git remote --verbose

Initial commit

$ git commit --allow-empty --message "Initial commit"
$ git push --set-upstream origin master

Create development branch

$ git checkout -b develop
$ git push --set-upstream origin develop
$ git branch --all

Merge upstream into development branch

$ git fetch upstream master
$ git merge --allow-unrelated-histories upstream/master
$ git push

Some changes on repository...

# Do some changes...
$ git add .
$ git commit -m "Some changes"
$ git push

Apply upstream changes...

$ git fetch upstream master
$ git log --all --graph --oneline
$ git merge upstream/master
$ git push

Merge development branch to master

$ git switch master
$ git merge develop
$ git push
$ git log --all --graph --oneline

For next clones:

Clone repository

$ git clone git@github.com:<username>/private-repo.git
$ cd private-repo

Add upstream remote

$ git remote add upstream git@github.com:<username>/public-repo.git
$ git remote --verbose

Switch to development branch and get upstream changes

$ git switch develop
$ git fetch upstream master
$ git log --all --graph --oneline
$ git merge upstream/master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment