Adding an existing project to GitHub using the command line
In this post, i will tell you how to push your existing projects on GitHub by command prompt.
Before going with this post i let you know some important tips :
Never push, commit or add sensitive information to a remote repository.
Sensitive information can be :
- API keys
- Credit card numbers
- PIN numbers
- SSH keys
- AWS access keys
I suggest you to remove sensitive data before putting any existing project on github.Step 1: Create a new repository
In this step, you will have to first create a new repository so that you can push your project in particular repository from terminal.Step 2: Initialize Git
To create a new Git repository, first open terminal and change directory to your local project and fire command
git init command from terminal, this will create empty Git repository.
$ git initStep 3: Add files to git repository
You have empty repository but nothing in it so start to add files with
You can add specific file by running following command :
$ git add <filename>
You can add all file by running following command :
$ git add .Step 4: Write a Git commit message
This is the best way to communicate context about a change to fellow developers that means if you make changes in any files and update this files on github with updated commit message then fellow developers can easily understand that changes are made in this files.
$ git commit -m "Add new files"Step 5: Adding a remote
You will have to first copy the remote repository URL :
You will have to run
git remote add to add new remote from your terminal.
This command will ask two arguments :
- A remote name, for example, origin
- A remote URL, for example https://github.com/ajaysoftdeveloper/expertphp.git
$ git remote add origin remote-repository-url # Sets a new remote $ git remote -v # verify new remote
If you are getting error :
remote origin already exists. then you can fix it by :
- Change name for the new remote
- Rename the existing remote
- Delete the existing remote
In this step simply push to the master branch by running following command :
$ git push origin master