Saturday, May 9, 2020

Create new repository and add existing project to GitHub in command line

Note: OS Windows
1. Create new repository on GitHub. Do not add README and gitignore files, can add it after push the project to GitHub.

2. Open Git Bash.
3. Change the current working directory to your local project.

4. Initialize the local folder as a git repository.
$ git init
5. Add file to the local repository(Stages) to first commit.(To unstage a file, use 'git reset HEAD YOUR-FILE')
$ git add .
6. Commit files staged in the local repository.
$ git commit -m "First commit"
7. Copy the remote repository URL on GitHub.
8. Add/set the URL for remote repository
$ git remote add origin <copied remote repository URL>
(Optional : To verify remote URL - $ git remote -v)
9. Push changes.
$ git push origin master

Reference:
[1] https://help.github.com/en/github/importing-your-projects-to-github/adding-an-existing-project-to-github-using-the-command-line

No comments:

Post a Comment