Help with Git

Published 1 month ago by Aaranihlus

Hi all,

I am new to using GitHub and I would like to ask a question on how to use it properly.

I have a server which I currently have a web app on.

I have a GitHub repository with my laravel project in it.

I downloaded my laravel project files from GitHub onto my server using git clone in the ssh terminal.

Now, I want to do some additional work on this project and push those changes to the live server, what is the recommended way of doing this?

Will I have to run npm run production to recompile all of my assets again? Will i have to reinstall all composer dependencies again?

I'm new to this and I'd really appreciate the help with all of the general workings of Git.

Thanks for reading Nathan

Best Answer (As Selected By Aaranihlus)
Thyrosis

Not necessarily install, more like reinstall.

So basically, the workflow is:

  1. Clone github locally.
  2. Create branch locally for the bugfix or feature you're working on
  3. Push branch to github
  4. Merge branch into master
  5. Pull master branch to live server
  6. On live, do a composer and npm install, run migrations and clear caches where necessary.

Regarding step 2, this can also include an upgrade to a new laravel version or just general update. So maybe the only thing you do is a 'composer update ' which, for git, will only change one single file: composer.lock.

But, based on that file, your live server will install the correct packages in step 6. Take care not to run 'composer update' on live (always do 'composer install'), as the update will search for any new version and creating its own composer.lock file in the process. Hello merge conflict!

Sergiu17
Sergiu17
1 month ago (193,930 XP)

Yes, you have to reinstall all the dependencies again. Because .gitignore file, ignores vendor directory. Learn more about CI/CD.

Thyrosis

Not necessarily install, more like reinstall.

So basically, the workflow is:

  1. Clone github locally.
  2. Create branch locally for the bugfix or feature you're working on
  3. Push branch to github
  4. Merge branch into master
  5. Pull master branch to live server
  6. On live, do a composer and npm install, run migrations and clear caches where necessary.

Regarding step 2, this can also include an upgrade to a new laravel version or just general update. So maybe the only thing you do is a 'composer update ' which, for git, will only change one single file: composer.lock.

But, based on that file, your live server will install the correct packages in step 6. Take care not to run 'composer update' on live (always do 'composer install'), as the update will search for any new version and creating its own composer.lock file in the process. Hello merge conflict!

hollyit

One of two methods. The best and least headache (once setup) is using some sort of CI/CD system. Personally I use Gitlab for everything (self hosted).

The other option is to create a bash script on the production server that does all the magic for you (git pull, npm run production, copy environment files, do route caching and whatever else you need).

Which choice I go with depends upon client/project needs. Something that won't be updated all that often, I just do the simple bash script. For more complex projects with frequent updates then CI/CD is the way to go and saves tons of headaches in the long run.

Please sign in or create an account to participate in this conversation.