Adding an existing project to GitHub using the command line

My way of adding project to GitHub

This is my shortest possible explanation, I am glad if someone finds this post useful.

This is for Linux users.

For Win and Mac user you can find instructions here, on the original GitHub documentation.

    1. Create a new repository on GitHub. To avoid errors, do not initialize the new repository with README, license, or gitignore files. You can add these files after your project has been pushed to GitHub.
    2. Open terminal.
    3. Change the current directory to local project directory.
    4. Initialize the local directory as Git repository.
      git init
      

      Add the files to the local repository. This stages (prepare) them for the first commit.

      git add .
      # To unstage a file, use 'git reset HEAD YOUR-FILE'.
      
    5. Commit files that you’ve staged in the local repository.
      git commit -m "First commit"
      # Commits the tracked changes and prepares them to be pushed to a remote repository. 
      # To remove this commit and modify the file, use 'git reset --soft HEAD~1' and commit and add the file again.
    6. At the top of your GitHub repository’s Quick Setup page, click to copy the remote repository URL.
    7. In Terminal, add the URL for the remote repository where your local repository will be pushed.
      # Sets the new remote
      git remote add origin "remote repository URL"
      
      # Verifies the new remote URL
      git remote -v
      
    8. Push the changes in your local repository to GitHub.
      git push origin master
      # In case on error add -f option to force

       

Leave a Comment

Your email address will not be published. Required fields are marked *