> ## Content Index
> Fetch the complete content index at: https://mfitzp.ghost.io/llms.txt
> Use this file to discover other available public pages before exploring further.

# Initialize Git Repository from Local Files
- URL: https://mfitzp.ghost.io/initialize-git-repository-from-local-files/
- Published: 2011-09-20T00:00:00.000Z
- Updated: 2026-09-09T09:03:41.000Z
- Description: Initialize a Git repository from a local directory, and the files therein, pushing it to an existing but empty remote.
- Author: Martin Fitzpatrick
- Tags: Tutorials, Git, #Import 2024-03-14 08:20, #Import 2026-08-24 14:26

### Requirements

- Git
- An empty bare remote repository

Open a terminal/console (Terminal on Mac/Linux, cmd.exe on Windows) and cd to the directory that will be added to Git.

Initialize the directory as an empty Git repository using the following command:

```bash
git init
```

Add the contents of the directory to the repo:

```bash
git stage .
git commit -m "Initial commit."
```

> *Alternatively add only some of the files by staging only those of interest and perhaps '.gitignore'ing the rest.*

Add the remote, replacing {remote} with the URI for the remote repository (for example, ssh://git.example.com/myrepo.git):

```bash
git remote add origin {remote}
```

Push the commit to the remote:

```bash
git push -u origin master
```

💡

**\-u adds a tracking reference for the branch which is useful for argument-less pull commands amongst others.*