GitHub is a cloud-hosted Git management tool for software development and version control. It offers the distributed version control and source code management functionality (SCM) of Git.
In this article, I'll show you how to use Git to push code to GitHub.
Step:1 Create a GitHub Repository
Sign in to GitHub and create a new repository. If you want, you can initialize the repository with README by selecting the
Add a README file option.
Step:2 Initialize git in the project folder
Run the following commands from the terminal inside the project folder:
$ git init
If you've already initialized git, you may skip this step.
This command generates a file named
.git in the project folder's root directory.
Add files to the index
$ git add -A
git add command is used to tell git which files to include in a commit, and the
-A argument is used to add all files to the commit.
- Commit added files
$ git commit -m "Initial commit"
git commitcommand is used to commit the newly added files, and the
-margument is used to specify the commit message.
Add remote origin
$ git remote add origin firstname.lastname@example.org:username/repo.git
Note: Remember to replace the
repowith your own.
Push code to GitHub
$ git push -u -f origin master
There are a few things to consider in this regard. The
-f flag represents force.
Everything in the remote directory will be overwritten automatically. We're only using it here to overwrite the README that GitHub generated automatically. If you skipped that step, the
-f flag isn't really required.
-u option makes the remote origin the default. This allows you to easily do git push and git pull later without having to specify an origin because we always want GitHub in this case.
$ git init $ git add -A $ git commit -m 'Initial commit' $ git remote add origin email@example.com:username/repo.git $ git push -u -f origin master
You can now use git to push code changes to GitHub.
Thank you for reading!