Reputation:
I'm using github to work on a project with two other people and am getting very confused about the whole commit thing, and nothing I'm reading is helping me understand. I get that commit records changes that you've made to a local repository... but then why are my group members' commits showing up on the online repository? Can you commit to both the local repository on your computer as well as an online repository? If you can commit to an online repository, what is the difference between doing that and simply using git push to push your changes online? Thank you kindly.
Upvotes: 2
Views: 334
Reputation: 30958
I guess you may have experience in SVN. Different from svn commit
, git commit
is merely a local operation. It generates data locally and doesn't send data to the remote repository. To publish your local changes, which are stored as commits, to the remote repository, you need git push
.
git push
sends local-only data to the remote repository and sometimes tells the remote repository to create or remove references like branches
and tags
. In theory, a remote repository can be any repository in the universe, as long as there is a functional path between your local repository and the remote one. Besides, the remote repository can even be the very same local repository itself. You can push from a repository to itself, although it's almost useless. You could try git push . HEAD:refs/heads/fmyself
.
After you successfully push commits (Yes, the push may fail but Git hints will tell you how to solve it), other people (more specifically other repositories. You yourself may have other repositories) can get your commits from the remote repository via git fetch
or git pull
. git pull
can be equivalent to git fetch + git merge
or git fetch + git rebase
. The key is git fetch
. It downloads meta data and references from the remote repository to the local one. As described above, other people can directly push to or fetch from your local repository and vice versa. However considering convenience and safety, this model is seldom used. More likely, a central repository is used. In your case, it's a repository hosted in Github. It works as a transfer station.
Some hosting services may support "online commit", which seems to allow you to directly commit in the remote repository. It's like you log in and do things in a repository on a server. Oneline commit is not that convenient in most cases except amending a commit message.
Upvotes: 0
Reputation: 58
but then why are my group members' commits showing up on the online repository?
answer: I would assume they've made commits to their local version of the repository then git push
ed those commits to the remote repository so that everyone else can see and pull down those changes.
If you can commit to an online repository, what is the difference between doing that and simply using git push to push your changes online?
answer: They are the same. I don't know anyone who makes commits directly to an online repository though (unless you are editing a README or making some simple HTML fix). Its general practice to make commits to the repository you have locally, then to push those changes up to the remote repository when you want to add it to the code base.
Upvotes: 1
Reputation: 1084
Let's say you are starting a new repository. You'd have to start local first, right? So,
git init
-> Initializes a repository on your local computer. (assuming you started with an empty folder)
Now you have an empty repository. Now it's time to add lots and lots of awesome code/content. Once you have some code, you will commit
.
git commit
-> Git will still keep all your changes locally; but remembers all the changes you made in this commit.
Let's say you make a couple of more changes, and want to save your work. So, you'll run the commit
again. Git again saves your changes, but in commit #2, still local to your computer.
Now you are ready to share your work with other people. Because Github repo's are online (typically), you will have to push
(i.e. upload) your changes to a remote repository.
Difference between commit
and push
is, the first one keeps all your changes locally on your computer (no one else in your team has access to your changes or commits), and push
will make your code available to everyone. Hope that's clear!
Upvotes: 0
Reputation: 414
There will be two stages of git commits.
Local repository commits: These are commits that you will doing to your local repository which is called staging the commits. These commits are not available for your friends as the name suggests these are local to your machine.
Online repository commits: These are commits that you will push from staging them to origin repository that is online. These commits will be available for all the users that are using this branch once they pull them.
Hope this clarifies and let me know if you need more information.
Upvotes: 0
Reputation: 11958
If your group members do a git push- it will push to the "online repository". Git commit only works on local. Git push is what moves those commits to the "online repository".
Upvotes: 0