Uploading to GitHub using Bash: 1-Minute Guide
GitHub is a platform where you can host your projects and files. Git is a command-line tool that allows you to track and host versions of files.
Here is your quick guide to uploading projects to a repository:
- Create a repository on your GitHub Profile.
2. Open Git Bash and move to the directory where your project is stored. My project is stored at C:\Users\Project. So I’ll use the command:
cd C:\Users\Project
3. Initialize this as your local repository for Git using the command:
git init
4. Add all files to the repository using the command:
git add .
To add a single file (say index.html), use the command:
git add index.html
5. Commit the files changed in your local repository.
git commit -m “This is a test commit”
You can put a description of your commit here.
6. Copy the URL to your repository on GitHub by clicking code and copying the URL shown (say https://github.com/codefinite-vri/Test-repo.git).
Then type the following command on Git Bash:
git remote add origin https://github.com/codefinite-vri/Test-repo.git
7. Name it as a remote repository.
git remote -v
8. Push the changes in your local repository to GitHub:
git push -f origin master
The -f forcibly pushes the files erasing any readme.md that already exists. Without this, you will get an error in case the readme.md isn’t existing in your local repository.
9. To pull files into your local repository, use the command:
git pull origin master
After uploading, steps 8 and 9 can be used as and when required. There is a lot that GitHub provides. Check out other functionalities of GitHub on the GitHub Documentation. All the best!