First, a note on file locations:
For instance, if I have /home/user/public_html/index.php and a git repo is located in /home/user/repo.git
This would be an unusual file layout. By default, every time you run git clone
you get two things:
- A checked out copy of all the files in a particular revision of the history; this might include files like "index.php" and "favicon.ico". This is known as the "working tree".
- A directory containing all the settings and version database, inside that directory. This directory is named
.git
(the .
there is not marking the file type, like in the MS-DOS/Windows convention, it's a leading dot meaning "hide from lists by default" in a Unix/Linux convention). This is what is mostly meant by "the repository".
Similarly, if you run git init
in an existing directory, it will by default create a .git
directory inside that directory.
So, if you have set up the directory /home/user/public_html
as a git working tree, your repository data will generally be in /home/user/public_html/.git
Second, notice that I used the word "database" when describing the .git
directory. That directory probably does not contain any files called "index.php". What it contains is enough data to reconstruct any version of that file that's in any branch of your git history.
Also contained in that directory is information about what version you currently have checked out in the working tree - what named local branch have you selected, what revision does that currently point to, and what do the files look like in that revision.
That's how git knows what changes you've made locally, for instance - it compares each file in the working tree with its knowledge of the currently checked out revision.
Before we get to git pull
, we need to understand git fetch
, because as discussed elsewhere, a git pull
is essentially a git fetch
followed by either a git merge
or git rebase
.
In git, any repository can track changes from any other - often, we have one local repository and one on GitHub / GitLab / etc, but git is not limited to that model. The way this works is that you "fetch" data from another repository (termed a "remote"), about its branches, commit history, and the content of those commits.
That data is then added to your local database (in the .git
directory) as a bunch of extra branches - the remote server's main
branch is kept separate from the local main
branch, for instance.
When you run git pull
, all of that happens, and then git compares the local branch you have checked out with one it fetched from the remote repository (by default, the one with the same name).
If the two branches it's comparing are pointing at different commits, then it will either (depending on various options):
- "fast-forward" the local branch to the same commit as the remote branch
- "merge" the two branches, creating a new commit which ties the two histories together
- "rebase" your current branch, recreating your local commits as though the full remote history had been there before you started
The result will be written to the working directory, and also into the local history database, as the new history for the current branch. All of this happens primarily at the level of commits, but every commit describes the content of every versioned file.
So...
What exactly is 'already up to date' ?
That message means "the remote branch you asked to synchronise with is the same as the local branch you have checked out, so there's nothing more to do".
It doesn't matter if you have local commits which are not on the remote repository, or even changes you haven't committed yet, only that your local branch history already contains everything the remote branch history contains.
does running git pull update the index file that's in the git repo or in public_html?
Both (sort of).
If there are changes that need to be pulled in to the current branch, git will calculate what the new history of the branch should be (using a fast-forward, a merge commit, or a rebase), and store it in the history database in the .git
directory. That includes what the content of "index.php" should be at the new tip of your branch.
Once it has worked that out, it will also update your working copy - the actual file "public_html/index.php" - so that it matches that updated local branch.