Getting files into a GitHub repository

Once you’ve created a repository, the next step is getting your code into it. You can do this through the GitHub web interface or from a local terminal. Both approaches work, but they suit different situations: the web interface is fine for a few small files, while the terminal is better for folders, projects, and larger file sets.

Adding a file through GitHub.com

You’ll need an existing repository to add files to. If you haven’t created one yet, use the “New repository” button, pick an owner, give it a name, choose public or private visibility, and initialize it with a README.md file.

Creating a new repository

Inside the repository, click the plus button next to the green “Code” button and select “Upload files.” On the following screen, click “choose your files” and select what you want to upload from your file browser.

An animated gif showing the process of adding files to a GitHub repo using the "Add files" button.

You’ll see the selected files listed on the commit screen. Keep in mind that they aren’t in the repository yet. Add a commit message in the provided box (the default is acceptable, though a brief description is more informative for collaborators), then click the green “Commit changes” button. The files are now part of your repository.

Pushing files from the terminal

For larger file sets, folders, or entire projects, the command line is the more practical route. Start by creating a new, empty repository on GitHub — enter only a name and description this time, and skip the README initialization so the directory is blank.

An animated gif showing the creation of a GitHub repository.

After creation, GitHub shows a set of terminal commands that mirror the steps below.

A screenshot of a newly created Git repository with instructions on how to add files to that repository using the command line

An animated gif showing the "git init" process for initializing a Git repository from the command line, as well as the process of adding files to a git commit.

On your local machine, open a terminal and change into the project directory you want to upload:

  1. Run git init to turn the folder into a Git repository.
  2. Create a README with touch README.md and add a brief description.
  3. Run git add . to stage all files in the current directory.
  4. Run git commit -m "initial commit" to record a snapshot of the current state.
  5. Run git status to confirm everything is staged and the working tree is clean.
  6. Run git branch -M main to set the default branch name.
  7. Run git remote add origin <repository-URL>, using the URL from the GitHub instructions page, to link your local repository to the remote one.
  8. Run git push -u origin main to upload the files.

Refresh the repository page in your browser, and the files should now be there.

If you already ran git init in a previous session, skip that first step and simply proceed from staging your files onward.