Here is how you can upload a file or a folder to your Github repository using Git Bash.
To push code to a Github Repository, we use this format:
$ git push <remote> <branch> --<flag>
The branch and flags are optional.
In this tutorial, we will learn how to add a local hosted repository to Github.
Before you can start, you need to understand:
- What is Git and Github
- Understand the basics of Gits
- Know how to Create a Repository on Github
- Have cloned the repository locally.
Follow this tutorial if you are trying to push code to Github using VS Code.
How to Push a File or Folder to Github (using Git Bash)
To push a folder or to sync a file from your local folder to your remote Github repository:
- Move your file to the cloned repository
- Open Git Bash
- Go to the current directory where you want the cloned directory to be added.
Inputcd
and add your folder location. You can add the folder location by dragging the folder to Git bash.$ cd '/c/Users/j-c.chouinard/My First Git Project'
- Add the file and stage it for commit
$ git add 'yourFileName.py
‘ - Commit the file to your local repository
$ git commit -m 'yourFileName.py
‘ - Push the changes to Github
$ git push origin master
For simplicity, I considered that you have not built work branches and that you commit straight to the master branch.
After all of this, your file will be committed to your Github repository.
Git Push Recap
In the command line, go to the root directory where your local files are. Optionally initialize the local directory (git init). Add the your file changes (git add) and commit your changes (git commit). Finally, push your changes of the local file or repository to GitHub (git push).
Git Commands Cheatsheet
To learn more about Git Commands, check out this Git Cheatsheet.
git config | Setup user information |
git init | Initialize a repository as a Git repository |
git clone [url] | Clone a local repository from Github |
git add [file path] | Add file or folder to your commit staging |
git commit -m “[message]” | Commit staged content |
git push [alias] [branch] | Push commit to Github |
git fetch [remote] [branch] | Download commits, files, and refs from remote to local repo |
git remote add [name] [url] | Modify a repository ./.git/config file |
git branch [branch] | Create, list, rename, and delete branches |
git diff [file path] | Compare last committed version of a file with the unstaged version. |
Interesting Git Push Flags
Git Push Flag | Definition |
---|---|
–force (-f) | F flag forces pushing deleting changes that may have happened since your last push |
–set-upstream (-u) | U Flag forces update only if the remote-tracking reference has been integrated locally. |
–verbose | V flag runs verbosely |
–progress | Forces the progress status on the standard error stream |
Other Version Control with Git and Github Posts
Learn Git and Github (Complete Guide)
Basics of Version Control
How to Use Git and Github with VSCode
Conclusion
You now know how to push a folder to Github and to upload files to repository using git.

SEO Strategist at Tripadvisor, ex- Seek (Melbourne, Australia). Specialized in technical SEO. Writer in Python, Information Retrieval, SEO and machine learning. Guest author at SearchEngineJournal, SearchEngineLand and OnCrawl.