How to push code into GitHub?
Pushing code into GitHub starts with creating a new repository.
What is a repository?
Repository is something that has the complete knowledge regarding the transformation of code. It also keeps a record of changes that are being made to the code. It also contains the revision history.
Advantages of storing code in a repository
- Systematic tracking of the changes that are being made in the code.
- Code backup.
- Centralised code storage.
- Collaborative working on a single code base.
Visit the following website and create an account by clicking on sign up or if there is already an existing account, login to the account by clicking on sign in.
Creating a new repository
- Click on “new repository” and enter name of the repository in the space provided.
- Choose if the repository needs to be visible to everyone or only to the user by clicking on “public” or “private”.
- Finally click on “create repository” and you’re done.
Pushing code into the new repository
Enter the following commands in command prompt to initialise a repository in your local folder.
``` git init ```
``` git add remote origin https://github.com/panidepu/example ```
This should be done for the first time when you intialise the repository.
Enter the following commands to push the code into repository everytime changes are made.
``` git add -A . ```
It adds all files from the current working directory to git index.
``` git commit -m “message” ```
This commits the code with the given message.
``` git push origin master ```
This pushes local master branch to remote.