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 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.
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
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:
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 firstname.lastname@example.org:discourse/discourse.git (fetch) discourse email@example.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 firstname.lastname@example.org:discourse/discourse.git (fetch) discourse email@example.com:discourse/discourse.git (push) custom-project firstname.lastname@example.org:your-username/custom-project.git (fetch) custom-project email@example.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…
-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