Skip to content

Instantly share code, notes, and snippets.

@sschmeier
Forked from DavideMontersino/private-fork.md
Last active August 5, 2020 08:59
Show Gist options
  • Save sschmeier/8b1c4a9b1fd3784f7cd20d0945fec551 to your computer and use it in GitHub Desktop.
Save sschmeier/8b1c4a9b1fd3784f7cd20d0945fec551 to your computer and use it in GitHub Desktop.
How to fork to a private gitlab instance

Private fork on GitLab

Aim

Have a public repo on github for the world to see + have a the same repo private on gitlab for project specific branches/dev. Locally use github as upstream and gitlab as origin. We develop in gitlab and push general applicable changes to our upstream github repo.

In detail:

  1. one for our private repository on gitlab (will be the default one, called origin)
  2. one to be connected to a repo on github, to be able to publish new general changes (will be called upstream)

Setup

How to make a private fork from github to gitlab

  # 1. clone the github project in your workspace
  git clone git@github.com:whatever/repo.git

  # 2. rename the remote
  git remote rename origin upstream

  # 3. Create a new repo in gitlab website

  # 4. Add the new origin to your repo

  git remote add origin git@gitlab.newname.git

  # 5. push to the private repository (track master)

  git push -u origin --all
  git push -u origin --tags

To push to gitlab / master, just use

   git push

To retrieve updates from github, use

   git pull upstream master
   git fetch --all --tags

Push new developments from a project branch to upstream, use

  git checkout -b project1
  
  # do whatever you want
  # push to private repo
  
  git push origin project1

  # Oh done some generally useful changes ...
  
  git checkout -b dev
  git merge project1  

  git push upstream dev
  
  # create a merge request with master on github
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment