• since git uses a system of "snapshots" of the entire codebase, git needs to know history of changes and show to all coders who did what at each moment in time.

It's a reasonable way to phrase it.

  • "commit" is like recording the changes in project's memory.

Yes, committing is adding a record of your changes (compared to the previous commit) on top of the branch.

  • uploading my changed version of the project,i.e. my branch to main online repo(master) is a different thing?

When you push, the remote server appends your changes to the remote branch provided that your history follows the server history. For example, if anyone has appended any change to the server history before you push, you are both showing divergent versions of the history from a certain point. So you need first to rewrite your local history so that it complies with the server's history. (usually using git pull, which will merge or rebase your branch depending on your choice)

  • when I upload my local changes to the main version of the project, my commits(recorded in .git file) become known to others.

Yes, when you push you let other know how you modified the history.

  • uploading changes to master branch is "pushing" all my commits, right?

Pushing is "uploading" (if you wish to use that word) your changes to the remote's master branch. As I said earlier, the remote will only accept if your changes are built upon the latest history available at the remote's master.

Note that all of this is true for any branch, you can have as many branches as you want, no only master.

Answer from Thibault D. on Stack Overflow
🌐
Git
git-scm.com › docs › git-commit
Git - git-commit Documentation
Create a new commit containing the current contents of the index and the given log message describing the changes. The new commit is a direct child of HEAD, usually the tip of the current branch, and the branch is updated to point to it (unless no branch is associated with the working tree, in which case HEAD is "detached" as described in git-checkout[1]).
🌐
W3Schools
w3schools.com › git › git_commit.asp
Git Commit
This commits all modified and deleted files, but not new/untracked files. git commit -a -m "Quick update to README" [master 123abcd] Quick update to README 1 file changed, 2 insertions(+)
🌐
GitLab
docs.gitlab.com › tutorials › make_first_git_commit
Tutorial: Make your first Git commit | GitLab Docs
When you work in a Git repository, you work in branches. By default, the contents of a repository are in a default branch. To make changes, you: Create your own branch, which is a snapshot of the default branch at the time you create it. Make changes and push them to your branch. Each push creates a commit...
🌐
GitKraken
gitkraken.com › home › learn › learn git: commit
Git Commit - How to Git Commit | Learn Git
March 24, 2021 - Learn how to Git commit in the CLI, including how to add a Git commit message and how to amend a commit. Then, see how to revert a commit with the GitKraken Git GUI.
🌐
Atlassian
atlassian.com › git › tutorials › saving-changes › git-commit
Git Commit | Atlassian Git Tutorial
At a high-level, Git can be thought of as a timeline management utility. Commits are the core building block units of a Git project timeline. Commits can be thought of as snapshots or milestones along the timeline of a Git project. Commits are created with the git commit command to capture the state of a project at that point in time.
🌐
GitHub
gist.github.com › luismts › 495d982e8c5b1a0ced4a57cf3d93cf60
Git Tips and Git Commit Best Practices · GitHub
Save luismts/495d982e8c5b1a0ced4a57cf3d93cf60 to your computer and use it in GitHub Desktop. ... A commit should be a wrapper for related changes. For example, fixing two different bugs should produce two separate commits. Small commits make it easier for other developers to understand the changes and roll them back if something went wrong.
🌐
GitHub
github.com › git-guides › git-commit
Git Guides - git commit · GitHub
You can make commits to different branches, and specify exactly what changes you want to include. Commits are created on the branch that you've currently checked out to (wherever HEAD is pointing) so it's always a good idea to run git status before making a commit, to check that you're checked out to the branch that you intend to be.
Find elsewhere
🌐
Git
git-scm.com › docs › gittutorial › 2.8.6
Git - gittutorial Documentation
If you need to make any further adjustments, do so now, and then add any newly modified content to the index. Finally, commit your changes with: ... This will again prompt you for a message describing the change, and then record a new version of the project. Alternatively, instead of running git ...
Top answer
1 of 3
3
  • since git uses a system of "snapshots" of the entire codebase, git needs to know history of changes and show to all coders who did what at each moment in time.

It's a reasonable way to phrase it.

  • "commit" is like recording the changes in project's memory.

Yes, committing is adding a record of your changes (compared to the previous commit) on top of the branch.

  • uploading my changed version of the project,i.e. my branch to main online repo(master) is a different thing?

When you push, the remote server appends your changes to the remote branch provided that your history follows the server history. For example, if anyone has appended any change to the server history before you push, you are both showing divergent versions of the history from a certain point. So you need first to rewrite your local history so that it complies with the server's history. (usually using git pull, which will merge or rebase your branch depending on your choice)

  • when I upload my local changes to the main version of the project, my commits(recorded in .git file) become known to others.

Yes, when you push you let other know how you modified the history.

  • uploading changes to master branch is "pushing" all my commits, right?

Pushing is "uploading" (if you wish to use that word) your changes to the remote's master branch. As I said earlier, the remote will only accept if your changes are built upon the latest history available at the remote's master.

Note that all of this is true for any branch, you can have as many branches as you want, no only master.

2 of 3
2

git basically uses these 3 things to store your data:

  • A blob is just a binary blob of stuff (your source code, an image, whatever). The blob does not contain information about the type or name of the content and is just a mass of bytes.
  • A tree points to one or more blobs, think "directory". It contains file names etc. of the blobs it points to.
  • A commit (the data object, not the git command) is a separate entity that points to exactly one tree (the state of all files at that point in time) and zero or more other commits (the parent(s), which may be missing for the very first commit in a repository, and which may be multiple in case of merges).

That's it. There's nothing else to it, conceptionally. In practice, there are branches and tags, but these are just special "sticky notes" pointing to commits. There are also mechanisms in place to reduce storage and such, but they are not of interest unless you hack on the code or go real deep.

Answering your question is easy in this context:

  • When you checkout a commit into your working directory, you get the files from one specific commit. Say, the sticky note (branch) master points to a commit afd876123, and you clone the repository into a fresh working directory, then you get the files represented in the tree that the commit afd876123 points to.
  • git of course keeps track and creates a special sticky note HEAD which stores the information that you are on master and on commit afd876123. It also creates an index which you can think of as an anonymous tree.
  • You edit some files in your working directory.
  • When you run git add, then git updates the index with your changes. While internally it works differently, you can think of it as updating the tree "index" with your changes.
  • No commit is associated with this tree (yet), so it is not a permanent thing; it does not affect pushes, pulls or whatever.
  • When you run git commit it creates a new commit object which points to the tree that is represented by your current index, as well as the previous commit afd876123 and other information (like timestamp, log message...). This commit object is then added to the data store and thus finalized.

The rest of your assumptions about push/pull are basically correct.

🌐
Linux Kernel
kernel.org › pub › software › scm › git › docs › git-commit.html
git-commit(1)
November 24, 2025 - Create a new commit containing the current contents of the index and the given log message describing the changes. The new commit is a direct child of HEAD, usually the tip of the current branch, and the branch is updated to point to it (unless no branch is associated with the working tree, in which case HEAD is "detached" as described in git-checkout(1)).
🌐
Openai
developers.openai.com › codex › app › worktrees
Worktrees – Codex app | OpenAI Developers
February 8, 2026 - When a branch is checked out, Git treats its HEAD as owned by that worktree and expects operations like commits, resets, rebases, and merges to advance that reference in a well-defined, serialized way.
🌐
CEI
cei.ai › home › insights › understanding git commit: a comprehensive guide
Git Commit Practices for Efficient Collaboration
March 20, 2025 - Each commit represents only the differences between versions. Git, by contrast, takes a distributed approach. When you commit in Git, you’re recording changes to your local repository, not immediately pushing those changes to a remote server.
🌐
Reddit
reddit.com › r/learnprogramming › what are 'git add' and 'git commit' doing and how are they different from each other?
r/learnprogramming on Reddit: What are 'git add' and 'git commit' doing and how are they different from each other?
June 8, 2017 -

I just learned the basics of github. I understand how to use it but don't quite understand why it is necessary to use 'git add --> git commit --> git push', instead of just 'git commit --> git push'.

I googled and found : "Add tells git to start tracking a file. ... You can combine both actions with git commit -a. Git commit commits the files in the index to the repository, git commit -a is a shortcut to add all the modified tracked files to the index first. Commit commits your current changes on your local repository.", but tbh I don't quite understand what it means, so perhaps I need an ELI5 version.

TL;DR: ELI5: What are 'git add' and 'git commit' doing, and how they are different from each other?

Top answer
1 of 2
4
git add tells git that it should track changes made to a particular file. Useful if you don't necessarily want to track all changes to all files in the index at every commit. git commit is like a save button. Up until that point all changes since the last commit are still just "staged" and not yet permanently written into the local git repo. This command tells git to permanently store changes made to the files you selected using git add as a node in the git tree. git commit -a is a shortcut for "save all changes to all known files in the index". It's the same as if you git add'ed all the files you're already tracking and then ran git commit. No new files will be tracked, so if something / someone writes junk like temporary files they won't get swept up into the repo. I understand how to use it but don't quite understand why it is necessary to use 'git add --> git commit --> git push', instead of just 'git commit --> git push'. It's just the way git is designed. At each commit you have to tell git "I want changes to these files to be tracked" (git add), "Save those changes to my local repo" (git commit), and "Send my changes to a remote repo" (git push). If all you want to do is track changes to the same files every time, that's what git commit -a is for.
2 of 2
3
So git works as a version control system because it stores the differences between different versions of files. This means that for every file in a directory that you want to keep track of, git must maintain a log of the differences that file experience in between each commit. This can take up a lot of space if git accidentally tracks something that you didn't want it too, for example an image file. Therefore, by default, git does not track any files when you create its root. Instead you must manually add files that you want it to track before each commit. This must be one before each commit because git has to know WHAT to commit. So add tell git "Hey this is a file im interested in, make sure to add it to my list of files to commit", whereas commit says "Im finished making changes, saves the changes to my interesting files as a commit." As and ease-of-use shortcut, the git developers added the -a option to commit to automatically add all files git knows about, but its simply running git add in the background.
🌐
cbeams
cbea.ms › git-commit
How to Write a Git Commit Message
May 27, 2023 - Compare that with these more recent commits from the same repository: $ git log --oneline -5 --author pwebb --before "Sat Aug 30 2014" 5ba3db6 Fix failing CompositePropertySourceTests 84564a0 Rework @PropertySource early parsing logic e142fd1 Add tests for ImportSelector meta-data 887815f Update docbook dependency and generate epub ac8326d Polish mockito usage
🌐
Git
git-scm.com › cheat-sheet
Git Cheat Sheet
git commit · git commit -m 'message' git commit -am 'message' git switch <name> OR git checkout <name> git switch -c <name> OR git checkout -b <name> git branch · git branch --sort=-committerdate · git branch -d <name> git branch -D <name> git diff HEAD ·
🌐
Microsoft Learn
learn.microsoft.com › en-us › visualstudio › version-control › git-make-commit
Make a Git commit in Visual Studio | Microsoft Learn
2 weeks ago - Git tracks file changes in your repo as you work, and separates the files in your repo into three categories. These changes are equivalent to what you would see when you enter the git status command in the command line: Unmodified files: These files haven't changed since your last commit.
🌐
Medium
medium.com › @miniliz454 › heres-what-i-learnt-about-git-commit-messages-fa67776bb423
HERE’S WHAT I LEARNT ABOUT GIT COMMIT MESSAGES
April 26, 2025 - A commit in Git captures the state of your code at different times, Commits saves progress, document changes and merges contributions from different collaborators or team members. When I first got…
🌐
CloudBees
cloudbees.com › blog › git-commit-detailed-tutorial-on-saving-your-code
Git Commit: A Detailed Tutorial on Saving Your Code
First, run the following commands to create and commit a second file: Great. Your repository now has two files. Let’s now change the first file: ... Now your two files are edited, and you can verify that by using the git status command.
🌐
Conventional Commits
conventionalcommits.org › en › v1.0.0
Conventional Commits
A commit body is free-form and MAY consist of any number of newline separated paragraphs. One or more footers MAY be provided one blank line after the body. Each footer MUST consist of a word token, followed by either a :<space> or <space># separator, followed by a string value (this is inspired by the git trailer convention).