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. As of Sept 2017, the following version is installed:
[server]$ which git /usr/bin/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 user.name "John Doe" [server]$ git config --global user.email [email protected]
This creates a file named .gitconfig in your user's directory with the following content:
[user] name = John Doe email = [email protected]
Check to confirm Git can find those settings by running the following:
[server]$ git config --list user.name=John Doe [email protected]
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.
[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 folder 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" [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: