This article assumes you're setting up your Git repository on your DreamHost server. View the SSH overview article for instructions on how to log into your server.
Git is installed on all DreamHost servers. Run the following commands to view the location and version.
[server]$ which git /usr/bin/git [server]$ git --version
How to set up Git for the first time
When you first set up your Git environment, you'll want to configure a few variables. View the following article for details:
You can also just proceed with the following steps for a basic setup.
Step 1 — Creating your identity
The following commands create your identity to be used with Git. View the SSH article for details on how to log into your server:
[server]$ git config --global user.name "John Doe" [server]$ git config --global user.email email@example.com
This creates a file named .gitconfig in your user's directory with the following content:
[user] name = John Doe email = firstname.lastname@example.org
Check to confirm Git can find those settings by running the following:
[server]$ git config --list user.name=John Doe email@example.com
Step 2 — Setting up the repository and commit
- Navigate to the directory of your application (or website). This example sets up Git in your website's directory. Change username to your Shell user and example.com to your website.
[server]$ cd /home/username/example.com
- Run the following to initialize the new repository:
[server]$ git init Initialized empty Git repository in /home/username/example.com/.git/
- This command creates the /.git directory and your git repository.
- Add all files in your app to the Git repository. The following command shows how to add all files:
[server]$ git add .
- You can also choose specific files if you wish.
- Run the status command to confirm which files are in the staging area:
[server]$ git status
Initial commit Changes to be committed: (use "git rm --cached ..." to unstage) new file: favicon.ico new file: images/image1.jpg new file: images/image2.jpg new file: images/image3.jpg new file: index.html new file: mystyles.css
In this example, you can see the following files and folders are being tracked and ready to be committed:
- If you're sure you're ready to commit (save) these versions of the files to your Git repository, run the following command:
Make sure to add a short and clear message that explains what this commit was for. View the following article for details on how to create a good commit message.
[server]$ git commit -m "Committing website files for the first time" [main (root-commit) e11cdb7] Committing website files for the first time 6 files changed, 34 insertions(+) create mode 100644 favicon.ico create mode 100644 images/image1.jpg create mode 100644 images/image2.jpg create mode 100644 images/image3.jpg create mode 100644 index.html
create mode 100644 mystyles.css
- The -m flag allows you to add a message to this commit.
This creates your first commit. You can see your commit history by running the following:
[server]$ git log --oneline e11cdb7 (HEAD -> main) Committing website files for the first time
You don't need the --oneline flag, this just shortens the response so it's easier to read. View the following link for further examples and explanations:
Step 3 — Configure the repository to use 'main' as the primary branch
Newly created repositories use the name master as the primary branch. To ensure future compatibility, it's recommended you now update this branch name to main. View the following article for further details: