Skip to content

Dear Internet Explorer user: Your browser is no longer supported

Please switch to a modern browser such as Microsoft Edge, Mozilla Firefox or Google Chrome to view this website's content.

Push local files to GitHub

Instructions for committing a folder of local files to a new GitHub repository via the Command Prompt.

GitHub is a useful tool for managing coding projects. If you have created a series of files on a local hard drive that you want to add to a GitHub repository, the procedure is quite simple.

Step 1: Create a repository

Log into GitHub and create a new repository via the following web interface:

Screen capture of GitHub
The GitHub interface showing the form for creating a new repository.

Note the new Git URL that is created in this process (for this example, it is https://github.com/AdamDimech/my-repository.git).

Screen capture of GitHub user interface.
Settings for the new GitHub repository.

Step 2: Prepare the local repository

Using the Command Prompt, cd to the local directory containing your files (in our example, the files are located at C:/Path/To/Folder”, so:

cd "C:/Path/To/Folder"

Next, enter the following command:

git init

The machine should respond with “Initialised empty Git repository in C:/Path/To/Folder/.git/”.

Next, enter the following:

git remote add origin https://github.com/AdamDimech/my-repository.git

Step 3: Push the files to GitHub

To select all files in the folder and sub-folders:

git add .

Commit the files with a description of what is happening:

git commit -m "Add existing file"

Push the files to the master branch of the repository on GitHub:

git push origin master
Screen capture of GitHub website.
An updated GitHub repository as seen in the web interface.

Your files should all be visible on GitHub.

Updating files following local changes

Of course, once you have created your repository and uploaded your files, you are almost certain to make changes locally as you keep working on your project. These changes will then require a ‘push’ to GitHub.

In the Command Prompt, specify the files that you want to update (ie: all of them) via:

git add .

‘Commit’ these files with an informative description (by changing Message to something meaningful):

git commit -am "Message"

Push the changes to GitHub

git push origin master

All of the changed files in the local directory will be uploaded to GitHub and versioned.

   

Comments

No comments have yet been submitted. Be the first!

Have Your Say

The following HTML is permitted:
<a href="" title=""> <b> <blockquote cite=""> <code> <em> <i> <q cite=""> <strike> <strong>

Comments will be published subject to the Editorial Policy.