What are the differences between "git commit" and "git push"?
Solution 1
Basically, git commit
"records changes to the repository" while git push
"updates remote refs along with associated objects". So the first one is used in connection with your local repository, while the latter one is used to interact with a remote repository.
Here is a nice picture from Oliver Steele, that explains the Git model and the commands:
Read more about git push
and git pull
on Pushing and pulling (the article I referred to first).
Solution 2
commit: adding changes to the local repository
push: to transfer the last commit(s) to a remote server
Solution 3
Well, basically Git commit puts your changes into your local repository, while git push sends your changes to the remote location.
Solution 4
git push
is used to add commits you have done on the local repository to a remote one. Together with git pull
, it allows people to collaborate.
Solution 5
Since Git is a distributed version control system, the difference is that commit will commit changes to your local repository, whereas push will push changes up to a remote repository.
ben
Updated on July 10, 2022Comments
-
ben almost 2 years
In a Git tutorial I'm going through,
git commit
is used to store the changes you've made.What is
git push
used for then? -
tanascius about 14 yearsHere is the original source: osteele.com/archives/2008/05/my-git-workflow with another picture of a git workflow
-
ben about 14 yearsAh that makes sense, thanks a lot! A quick follow up if I may, in the tute I'm doing, the author makes it seem like setting up GitHub is totally optional, but then starts using git push. Does using push send to GitHub, if that's what you've setup?
-
tanascius about 14 years@ben: Yes, when github is your remote repository, a
push
will sent to github - see here for making github the remote repository: github.com/guides/… -
Santa about 14 years@ben github is but one solution to host your public, "on-the-cloud", repository for
git push
to work with. In reality, the destination ofgit push
can be any git repository. It can be on your own local hard drive in another directory (git remote add clone ~/proj/clone.git; git push clone master
orgit push ~/proj/clone.git master
, for example), or a git repository that your own host serves. -
Abdullah almost 11 yearsthis is my second day of using GIT. As I look at the answers above, i still don't get a clear picture, but your answer just nails it. thanks.
-
Admin over 10 yearsYour answer is basically identical to this answer, it doesn't add anything new.
-
Kokodoko about 10 yearsso... do you need to push first or commit first?
-
tanascius about 10 years@Piet it starts at your workspace, where you modify files. Then you add them to the index, commit them to the local repository and - finally - push them to the remote repository
-
Celik over 9 yearsWhy push and commit are separated? When I commit something, I always push it at the same time. So, why I need both of them separately? note: I know commit works locally, push works for remotely. Any other reason or usage?
-
Admin over 9 yearsSome people may want to force push instead of pull. It depends on the situation. In fact, if you're rebased commits on a branch that you're not sharing with other people (even on a remote repo), then pulling is certainly not what you want to do.
-
Vlas Bashynskyi over 9 yearsSo when i edit a file in a text editor i don't change files in my local repository, right? Where are my local repository files stored then?
-
tanascius over 9 years@Celik When you have no remote repository, a push is useless. So the separation makes sense. But there might be more then one remote repostitory as well - so you have to push multiple times.
-
tanascius over 9 years@VLAS Have a look at stackoverflow.com/questions/3082445/where-does-git-store-files ... basically they are stored in a hidden subfolder called
.git
-
Celik over 9 years@tanascius one command is still enough. If there is a remote repo, this command pushes it. if there is no remote commit it. Still second one is useless. for the multiple repo,one command is still enough. e.g: git push repo1 repo2 .... I can push them all with one command.
-
Qwerty over 9 yearsSo, do I
Commit, Pull, Push, Sync
, orPull, Sync, Commit, Push
? -
hellodear almost 9 years@tanascius when I change file locally that is my local repository, right? when I go in .git, do u mean in .git we have some other copy of the files which I am editing? when I say commit, then these files .git are over-written by the workspace file? Please tell.
-
Dr.jacky almost 8 years@tanascius Is that possible to remove local repository from scenario, and commit changes to remote repository directly?
-
tanascius almost 8 years@Mr.Hyde no that is not possible. Git as a distributed version control requires you to have a local copy.
-
Dr.jacky almost 8 years@tanascius How about doing something in this question: stackoverflow.com/questions/38291364/…
-
yathirigan over 7 yearsDoes push mean a new version release of that library ?
-
Mehrdad Salimi almost 7 years@GreenMatt the link is not available anymore. may you replace it. thanks
-
GreenMatt almost 7 years@MehrdadSComputer: Huh? Not sure which link you mean, but my only comment on here contains no link. Did you mean to direct that to someone else?
-
Mehrdad Salimi almost 7 years@GreenMatt ops. I am really sorry. I should have directed the post owner (tanascius)
-
tanascius almost 7 years@GreenMatt: I corrected the link - it is working again, now
-
Gobliins almost 7 yearsDoes
git push
automatically push code into my currently feature branch or do i have to manually entergit push origin branch
? -
Kaschwenk about 6 yearsOriginal source link from @tanascius is broken, here is the current one: blog.osteele.com/2008/05/my-git-workflow
-
Nesha Zoric almost 6 yearsThank you for the great answer. It helped me out to get a better understanding. This article also helped me to get a better understanding of how other git commands work as well.
-
Legends almost 6 yearsWhat is a workspace and what is a local repository ??? I thought this is the same and my repo on github is my remote repo..?!
-
equivalent8 over 5 yearsto fully understand git watch this advanced talk youtube.com/watch?v=1ffBJ4sVUb4
-
multigoodverse over 5 yearsDoes
git push
uploads the actual updated files or some special "diff" file? -
Sumax almost 5 years@Gobliins: hope it's not too late; yes you are right you must specify
git push origin branch
, for eg: 'branch' = 'master' if you are updating the main repo. -
Erik Thysell almost 4 years@tanascius Thankyou so much, been looking for so long for a simple picture like this!
-
Lathryx over 3 yearsFrom what I understand, "commit" is essentially "staging" the changes, whilst "push" is actually making those changes. If anything it sounds better the other way around in my opinion. Thanks, though!
-
pholpar almost 3 yearsThe original version as referred by @tanascius is not available any more. See the archived version here: web.archive.org/web/20080807222046/http://osteele.com/archives/…
-
Dave F over 2 yearsGreat concise answer! Many answers on here are unnecessarily long.
-
Peter Mortensen almost 2 yearsWhat does "Snapshot | Changeset | Version | History-record" mean? E.g., does it refer to a particular application or web site?
-
Peter Mortensen almost 2 yearsWhat do you mean by "Checkit (.git) file get created" (seems incomprehensible)? Please respond by editing (changing) your answer, not here in comments (without "Edit:", "Update:", or similar - the answer should appear as if it was written today).
-
Peter Mortensen almost 2 yearsOK, the OP has left the building: "Last seen more than 3 years go"
-
xged almost 2 years@PeterMortensen No. These are just different possible general descriptors.