Best way to setup a private customised discourse repo


(James Cook) #1

I want to be able to customise discourse so I have forked the repo and I’m able to pull the latest discourse updates and merge them into my repo’s master branch.

However, I’m unable to make my repo private because it’s forked from a public repo.

Obviously I’m going to be adding things to my own personal discourse installation that I don’t just want anybody to be able to pull down and clone my website.

What would be the best way of going about doing this?

Should I just clone the discourse repo (not fork it) and push to my own private repo instead. Would this work? Would I still be able to get the latest discourse updates and merge them in?

Thanks for your help :slight_smile:


How to customize your own discourse and deploy it to production on Ubuntu for beginners
Integrating a customized highlight.js into my forum
How to upgrade and maintain the discourse source code if I use discourse for my own discussion forum
Updating to newer version of Discourse after doing custom changes
(Ilya Kuchaev) #2

Clone Discourse locally, push it to your private repo then. That is it.


(James Cook) #3

Will this still allow me to pull the latest changes from the Discourse repo and merge them in to my repo?


(Benjamin Kampmann) #4

Yes. It will keep the reference.

I recommend having your own branch (my-private-version) branched off master, which you merge master (or stable) into whenever you deem right. Especially if you do incompatible changes and want to test things on vanilla master, this helps keeping better track of changes.

I have a setup with multiple remotes, working on normal discourse vanilla, a private client project and my own OS versions.


(James Cook) #5

Ok so for anybody else reading this with the same question it appears quite easy to set up. I’ve written the following guide below. Apologies to anyone that feels this is basic stuff, but I’m sure some people will find this helpful if they are relatively new to git.

Clone Discourse

Clone the latest code from the discourse repo to a local folder on your computer.

Custom Folder Name

By default, cloning a project creates a folder with the same name of the repo. In this instance it will be saved in a folder called discourse. If you want it to be in a different folder (this is your own custom project after all) you can add a name after the clone command to set the name of the created folder. For example:

This will then clone Discourse and put it in a folder called custom-project.

Create a corresponding repository

Log in to your github account and create a new repository. Call it whatever you like. For the sake of this tutorial though we’ll call it custom-project

However, don’t do anything with it just yet.

Remotes

First of all, if the concept of remotes is confusing for you, or you’ve only ever used origin then please take a look here: Git Basics - Working with Remotes

Renaming origin

Go back to your terminal and to your cloned discourse folder. You will now have the default remote in your project called origin which will point to the Discourse repo on github for both fetching and pushing. You can see this by typing: git remote

The idea of setting up your own custom Discourse repo is so that you can pull the latest changes from the main Discourse repo and merge them in to your own custom repo. The point of this is so that you can customise your own site to your heart’s content and still be able to keep up to date with the main Discourse app.

Therefore, I thought it would be less confusing to rename origin to discourse by running the following command:

If you now run:

you should see this in your terminal:

discourse git@github.com:discourse/discourse.git (fetch) discourse git@github.com:discourse/discourse.git (push)

As you can see, the discourse remote points to the main discourse repository on github.

Adding a new remote

We’re now going to add a new remote to our project that points to the repository you created earlier. Run the following command, but replace it with the url of your repository, and obviously change the name of custom-project to whatever your project name is.

If you now run:

you should now see this:

discourse git@github.com:discourse/discourse.git (fetch) discourse git@github.com:discourse/discourse.git (push) custom-project git@github.com:your-username/custom-project.git (fetch) custom-project git@github.com:your-username/custom-project.git (push)

So you now have your two remotes set up. One to grab the latest changes from the main Discourse repository, and another to keep track of any modifications you make to your own personal site. We now need to set up different branches to manage these two locations…

Setting Up Your Branches

Set up your master branch

By default you should be on the master branch of your project. It is currently set up to track the discourse remote which we renamed earlier. However, we want the master branch to be the master branch for your custom project. Run the following command to push this branch to your custom repo and to set the default remote all in one go…

The -u is shorthand for setting the default upstream (remote). In this case we’re setting it to custom-project (which points to your custom repository) and we’re naming the remote branch master, the same as the local branch we’re currently on. This will now push the current code to your custom repository and remember that remote for next time.

###Creating a branch to pull the latest Discourse changes

Now that we have our master branch set up and tracking our own repository, we need to create a branch exclusively for pulling the latest changes from Discourse so that we can merge these straight into master. This is of course optional. You could merge changes from the discourse remote straight into your master branch, but by doing it this way you’ll always have an up to date vanilla Discourse to poke around in if you have/want to.

Go ahead and create a new branch by running the following:

You can call this whatever you want, but I’ve kept things simple by calling it discourse-master. This will of course still be pointing to your repository, not the main Discourse repo. However, I’ve decided to keep it this way.

It is possible to set up different pushing and fetching remotes for this new branch (in order to fetch from Discourse and push to your repo) however I prefer to keep fetching and pushing pointing to the same place, again to avoid confusion. If you would like to set up different URLs, please see this link: Different Git Push and Pull URLs

Assuming you’re going to leave discourse-master pointing to your repository then you can run the following command to pull the latest changes from the Discourse repository:

This will pull the latest changes from the master branch of the discourse remote into your current local branch, which in this case is discourse-master. You can then push this updated branch to your repo by running:

or if you want to be explicit:

You should now be fully set up to start customising Discourse in your own repository while still having access to any changes that are merged in to the original repository.

I’m a relative beginner myself, so if there are better ways to do this, or if I’ve missed anything, or if you disagree with something please reply and I’ll change the guide accordingly :slight_smile:


Why I ditched my custom discourse install, and went with the easy option
(Love Chopra ) #6

Thanks a lot @jamesmarkcook, really appreciate your detailed explanation, would be really great if you can summarize your flow in a simple graphical diagram, this will really going to help all who are beginners