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:
Note the new Git URL that is created in this process (for this example, it is https://github.com/AdamDimech/my-repository.git
).
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
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!