Pushing your DreamHost Git repository to GitHub


It's always a good idea to keep a copy of your repository on an external server in case your local copy is deleted. There are two general ways you can go about this:

  • Create your application and Git repository on your DreamHost server. Then, you can push to GitHub
  • Create your application and Git repository on your home computer. Once it's ready, push the repo to your DreamHost server.

This article explains how to push your repository on your DreamHost server to GitHub.

If you do not want to use GitHub, you can still create your site on your home computer, then push it to a repository on your DreamHost web server. View the following articles for instructions on how to do this:

Create a token

It's no longer possible to use a password when pushing a repository to github.com, so you must first create an access token before proceeding. This token will then act as a password when committing to your repository. View the following article for more information:

When creating your token, make sure to configure the following: 

  • Repository access: Access to the repository you are pushing to
  • Permissions: Under Repository permissions, enable access to the Contents permission. This allows you to use the push command as described below.

You will see the following error if these permissions are not configured:

The requested URL returned error: 403

Configure your DreamHost repository to use 'main' as the primary branch

If you have not created a local repository for your DreamHost files yet

View the following article to configure your DreamHost repository:

If you have already created a local repository for your DreamHost files

This step is not required but will help to ensure future compatibility with third-party git software programs like github.com.

If you've already created a local repository on your DreamHost server, the primary branch name is master. You may want to update this to main to avoid future compatibility issues. View the following article for further information and instructions on how to change the branch name.

Pushing your DreamHost repository to GitHub

If you've developed your site on your DreamHost server, it's recommended to put a copy on GitHub for two main purposes:

  • This creates an external backup of your code, and
  • It makes future collaboration with other developers much easier.

Follow these steps to push your repository to GitHub

  1. Sign up at GitHub.
  2. Create a public or private repository in your GitHub account.

    Since you're pushing your repository to GitHub, do not initialize the new repository with a README, license, or gitignore files. You can add these files after your project has been pushed to GitHub if needed.

  3. Once created, github.com shows you several commands to run to push your git repository to their servers.
  4. Log into your DreamHost server via SSH and navigate to your application folder where you set up your git repository.
  5. Run the following command to push your app to GitHub:

    The word origin is just an alias. It can be named anything you want. But this alias name will be used when you push your content to github.com as shown in the next step.

    repo_name is the name of the repository you created at github.com. Make sure .git is at the end.

    [server]$ git remote add origin https://github.com/github_username/repo_name.git
    [server]$ git push -u origin main

    When you run the push command, you are prompted for your github username and password. Enter the token you created above in the password field.

    View the following links for details:
  6. Visit your repository at github.com and you'll see that all files have been added.

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?