How to Push an existing Local project to Live on GitHub Using the Command Line

How to Push an existing Local project to Live on GitHub using the Command Line

 2,838 total views,  2 views today

Note: Article updated at 14th May, 2020.

Hello everyone, Welcome to blog.sunnydoshi.in, This blog post covers Laravel existing local application to live on Github using command line.

If you want to make laravel app, then checkout beginner tutorial for Laravel 5 Basic Auth Installation. It will built your first app with Laravel Authentication in local.

Prerequisite

  • Know how to use GIT, Terminal etc.
  • Have a local working copy ready.
  • Have SSH access to your server using private/public key.
Should I commit the dependencies in my vendor directory?

The general recommendation is no. The best practice is to then have all the developers use Composer to install the dependencies. The vendor directory (or wherever your dependencies are installed) should be added to .gitignore / svn:ignore/ etc.

By default to make the installation process smooth, I recommend remove these files and Later You might want to modify your .gitignore file to add them.
config.php and laravel.log files

Remove file path: xampp\htdocs\laravelbasicauth\bootstrap\cache\config.php
Remove file path: xampp\htdocs\laravelbasicauth\storage\logs\laravel.log

Have a local working copy ready

I assume we are working on master – but you could work on any branch.

– Open Github and signup account, After login Create a new repository
– At the top right of any Github page, you should see a ‘+’ icon. Click that, then select ‘New Repository’.
– Give your repository a name–ideally the same name as your local project. If I’m building a basic auth application, its folder will be called ‘laravelbasicauth’ on my computer, and ‘laravelbasicauth ‘ will be the Github repository name as well. Click ‘Create Repository’.

Create New Repository – blog.sunnydoshi.in

Open Git Bash, and Redirect to desired directory (project root folder) where your laravel code, Type the following command there to Initialize the local directory as a Git repository:

$ git init

Adds the files in the local repository and stages them for commit. To unstage a file, use ‘git reset HEAD YOUR-FILE’. This stages them for the first commit. Run the following command:

$ git add .
# This is the first command that you'll run after making some changes to the project files. It will Stage all files.

# If you want to do add specific multiple file in stage, we need to use this command with space seperated:
Syntax: git add <directoryname/filename_with_extension>
$ git add application/controllers/Taxfiles.php application/views/tax_category.php

Commit the files that you’ve staged in your local repository. Run the following command:

$ git commit -m "Initial 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.

If you are push code local to live on github. Then it should be authenticated user, Run following command to authanticate user:

To set your global username/email configuration:
$ git config --global user.name "Your Name"
$ git config --global user.email "Your Email"

To set repository-specific username/email configuration:
$ git config user.name "Your Name"
$ git config user.email "Your Email"

At the top of your GitHub repository’s Quick Setup page, click  to copy the remote repository URL and run the following command:

$ git remote add origin <remote repository URL>

For Verifies the new remote URL run the following command:

$ git remote -v

Check which branch you are working on for that run the following command:

$ git branch

Check if there are already some changes tracked in the repository by git? git status will list any files that are changed. Check file status, run the following command:

$ git status

Push the changes in your local repository to GitHub. The default branch is master that always exists on any repository. Run the following command:

$ git push origin master

Go back to the Github repository screen on Github that you just left, and refresh it. The title ‘Quick setup — if you’ve done this kind of thing before’ should disappear, and you should see your files there.

Done!

Feedback

If you have any feedback to improve it, feel free to make a suggestion, or open a PR!

Official Documentation

Documentation for the github project steps can be found on the Github Help.

I hope you learned something. If you did, feel free to share this article with a friend or on social media. Let me know if you have any questions, comments or feedback – either via Twitter or email.

Stay Safe At Home. Learn Something New. Share To The World.
Happy Coding 😊

Also, don’t hesitate to subscribe to newsletter if you like this article.

Share this post

Related posts