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:
- Pushing your local Git repository to a DreamHost server — Windows
- Pushing your local Git repository to a DreamHost server — Linux & Mac OS X
Create a github.com token
Before proceeding, make sure you first create a new token in github. It's no longer possible to use a password when pushing a repository to github.com, so you must create an access token to continue.
This token will act as a password when committing your repository. View the following article for more information:
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
- Sign up at GitHub.
- 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.
- Once created, github.com shows you several commands to run to push your git repository to their servers.
- Log into your DreamHost server via SSH and navigate to your application folder where you set up your git repository.
- 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.
- Visit your repository at github.com and you'll see that all files have been added.