-3

Can any of you pros please educate me on what the main differences are between git add, git commit, and git push, and when do you decide what to use? I understand the purpose is to ultimately save them in your repository but I'm still confused as to how they are being used.

Daniel
  • 3
  • 2
  • If you `commit` without doing `add`, nothing happens because nothing has been added to "staging" aka "the index". If you `push` without doing `commit`, nothing happens because there is no local commit to push to the upstream remote. `git status` is also important, it shows you what is not added and what is added. `git log` is also important, it shows you what has been commited and what has been pushed. – Mike Kim Dec 30 '22 at 09:58

1 Answers1

0

I think you are new to git.. Let me explain them in a way you understand.

First you need to understand, there are three areas: Working directory, staging area, repository.

  • Working directory is the place you are working in, i.e, your folder/files.
  • Staging area is the intermediate stage between your working directory and repository. You stage the required files here before you commit to the repository.
  • And the reopsitory is the .git folder where all your commits are stored

git add <files> is used to transfer your files in the working directory to the staging area.

git commit is used to move those files in the staging area to the repo by making a commit.

git push is something different. It do not make changes to your local git repo, but instead it will transfer your entire git repo to a cloud hosting service like github, gitlab, etc.....

Vikash
  • 194
  • 2
  • 9