How do I set up a Git repository?

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.

Pre-installed Git

Git is installed on all DreamHost servers. As of Sept 2017, the following version is installed:

[server]$ which git
[server]$ git --version
git version 2.7.3

How to set up Git for the first time

When you first set up you 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.

Creating your identity

The following two commands create your username and email address to be used with Git. View the SSH article for details on how to log into your server:

[server]$ git config --global "John Doe"
[server]$ git config --global

This creates a file named .gitconfig in your user's directory with the following content:

        name = John Doe
        email =

Check to confirm Git can find those settings by running the following:

[server]$ git config --list Doe

Setting up the repository and commit

  1. Navigate to the directory of your application (or website). This example sets up Git in your website's directory.
    [server]$ cd /home/username/
  2. Run the following to initialize the new repository:
    [server]$ git init
    Initialized empty Git repository in /home/username/
    This command creates the /.git directory and your git repository.
  3. 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.
  4. 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 folder are being tracked and ready to be committed:

    • favicon.ico
    • images/image1.jpg
    • images/image2.jpg
    • images/image3.jpg
    • index.html
    • mystyles.css
  5. 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"
    [master (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 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:

See also

Did this article answer your questions?

Article last updated .