Search code examples
reactjsgitgithub-pages

Why are terminal commands 'git add .', git commit...' and 'git push...' listed as optional when deploying React project?


Apologies, I am still a bit confused by git, although I am trying to teach myself more and improve.

I recently successfully deployed a React website to GitHub pages, following the often recommended steps of installing gh-pages to the project, adding a homepage property to the package.json file, adding scripts to the scripts properties on the package.json file, running 'npm run deploy' and so on. It worked fine, and now a build of the project has been added to my repository (here), and I can view the actual project online (here).

However, the issue I have is this: most guides on deploying a react app also mention the following steps: in the terminal type:

git add .

git commit -m "commit"

git push origin master

These final steps are often listed as optional. Everything worked fine without me doing these steps: my code was added to the repository, and my website is deployed online, so what do these steps do exactly? Why are they considered optional? What is best practice?


Solution

  • These commands are not optional to me - when using only the command-line Git client, these commands accomplish the interaction of pushing the code (that, after you edit it, only exists locally on your own PC) to the Git repository server.

    Everything worked fine without me doing these steps: my code was added to the repository, and my website is deployed online

    I can see the following possibilities:

    • You are using another Git client and the push was done there;
    • You are using a Git tool (e.g. editing purely on the GitHub website), where the push happened without you being aware of it;
    • You did the terminal commands, without being aware of them;

    A common resource to learn more about Git would be the Git book on the official Git SCM website: https://git-scm.com/book/en/v2