[git] Git: add vs push vs commit

What is the difference between git add, push and commit?

Just a little confused coming from SVN, where "update" will 'add' stuff, and commit does a "push" and will 'add' as well

There are all different functions within git. Hoping for some explanation from your experience.

This question is related to git repository push commit add

The answer is


I find this image very meaningful :

enter image description here

(from : Oliver Steele -My Git Workflow (2008) )


  • git add adds files to the Git index, which is a staging area for objects prepared to be commited.
  • 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.
  • git push sends all the pending changes to the remote repository to which your branch is mapped (eg. on GitHub).

In order to understand Git you would need to invest more effort than just glancing over the documentation, but it's definitely worth it. Just don't try to map Git commands directly to Subversion, as most of them don't have a direct counterpart.


I was confused about what 'add' really does. I just read a very enlightening paragraph from the book Git Pro that I'd like to add here, because it clarifies things

“It turns out that Git stages a file exactly as it is when you run the git add command. If you commit now, the version of benchmarks.rb as it was when you last ran the git add command is how it will go into the commit, not the version of the file as it looks in your working directory when you run git commit. If you modify a file after you run git add, you have to run git add again to stage the latest version of the file:”

Excerpt From: Chacon, Scott. “Pro Git.” Springer, 2009-08-19T00:00:00+00:00. iBooks. This material may be protected by copyright.


Very nice pdf about many GIT secrets.

Add is same as svn's add (how ever sometimes it is used to mark file resolved).

Commit also is same as svn's , but it commit change into your local repository.


add tells git to start tracking a file.

commit commits your current changes on your local repository

push pushes you local repo upstream.


git add selects changes

git commit records changes LOCALLY

git push shares changes


add -in git is used to tell git which files we want to commit, it puts files to the staging area

commit- in git is used to save files on to local machine so that if we make any changes or even delete the files we can still recover our committed files

push - if we commit our files on the local machine they are still prone to be lost if our local machine gets lost, gets damaged, etc, to keep our files safe or to share our files usually we want to keep our files on a remote repository like Github. To save on remote repositories we use push

example Staging a file named index.html git add index.html

Committing a file that is staged git commit -m 'name of your commit'

Pushing a file to Github git push origin master


Examples related to git

Does the target directory for a git clone have to match the repo name? Git fatal: protocol 'https' is not supported Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) git clone: Authentication failed for <URL> destination path already exists and is not an empty directory SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 GitLab remote: HTTP Basic: Access denied and fatal Authentication How can I switch to another branch in git? VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio?

Examples related to repository

Kubernetes Pod fails with CrashLoopBackOff Project vs Repository in GitHub How to manually deploy artifacts in Nexus Repository Manager OSS 3 How to return a custom object from a Spring Data JPA GROUP BY query How do I force Maven to use my local repository rather than going out to remote repos to retrieve artifacts? How do I rename both a Git local and remote branch name? Can't Autowire @Repository annotated interface in Spring Boot How should I deal with "package 'xxx' is not available (for R version x.y.z)" warning? git repo says it's up-to-date after pull but files are not updated Transfer git repositories from GitLab to GitHub - can we, how to and pitfalls (if any)?

Examples related to push

Best way to "push" into C# array Firebase: how to generate a unique numeric ID for key? Why does Git tell me "No such remote 'origin'" when I try to push to origin? Unknown SSL protocol error in connection Git push rejected "non-fast-forward" How to add multiple files to Git at the same time git push to specific branch Declare an empty two-dimensional array in Javascript? What does '--set-upstream' do? fatal: 'origin' does not appear to be a git repository

Examples related to commit

git: updates were rejected because the remote contains work that you do not have locally How to add multiple files to Git at the same time Why Git is not allowing me to commit even after configuration? Git commit in terminal opens VIM, but can't get back to terminal How to configure Git post commit hook GIT commit as different user without email / or only email Editing the git commit message in GitHub How to amend a commit without changing commit message (reusing the previous one)? Temporarily switch working copy to a specific Git commit git - Your branch is ahead of 'origin/master' by 1 commit

Examples related to add

Add a new item to recyclerview programmatically? momentJS date string add 5 days How to add an object to an ArrayList in Java ListView with Add and Delete Buttons in each Row in android How to add new column to MYSQL table? How to add text to an existing div with jquery Datetime in C# add days How to add hours to current time in python How To Add An "a href" Link To A "div"? How to use ArrayList.addAll()?