rsync -rL rsync://rsync.kernel.org/pub/scm/git/git.git/ .git
----------------
followed by
----------------
$ git read-tree HEAD
----------------
to populate the index. However, now you have populated the index, and
you have all the Git internal files, but you will notice that you don't
actually have any of the working tree files to work on. To get
those, you'd check them out with
----------------
$ git checkout-index -u -a
----------------
where the `-u` flag means that you want the checkout to keep the index
up to date (so that you don't have to refresh it afterward), and the
`-a` flag means "check out all files" (if you have a stale copy or an
older version of a checked out tree you may also need to add the `-f`
flag first, to tell 'git checkout-index' to *force* overwriting of any old
files).
Again, this can all be simplified with
----------------
$ git clone git://git.kernel.org/pub/scm/git/git.git/ my-git
$ cd my-git
$ git checkout
----------------
which will end up doing all of the above for you.
You have now successfully copied somebody else's (mine) remote
repository, and checked it out.
Creating a new branch
---------------------
Branches in Git are really nothing more than pointers into the Git
object database from within the `.git/refs/` subdirectory, and as we
already discussed, the `HEAD` branch is nothing but a symlink to one of
these object pointers.
You can at any time create a new branch by just picking an arbitrary
point in the project history, and just writing the SHA-1 name of that
object into a file under `.git/refs/heads/`. You can use any filename you
want (and indeed, subdirectories), but the convention is that the
"normal" branch is called `master`. That's just a convention, though,
and nothing enforces it.
To show that as an example, let's go back to the git-tutorial repository we
used earlier, and create a branch in it. You do that by simply just
saying that you want to check out a new branch:
------------
$ git switch -c mybranch
------------
will create a new branch based at the current `HEAD` position, and switch
to it.
[NOTE]
================================================
If you make the decision to start your new branch at some
other point in the history than the current `HEAD`, you can do so by
just telling 'git switch' what the base of the checkout would be.
In other words, if you have an earlier tag or branch, you'd just do
------------
$ git switch -c mybranch earlier-commit
------------
and it would create the new branch `mybranch` at the earlier commit,
and check out the state at that time.
================================================
You can always just jump back to your original `master` branch by doing
------------
$ git switch master
------------
(or any other branch-name, for that matter) and if you forget which
branch you happen to be on, a simple
------------
$ cat .git/HEAD
------------
will tell you where it's pointing. To get the list of branches
you have, you can say
------------
$ git branch
------------
which used to be nothing more than a simple script around `ls .git/refs/heads`.
There will be an asterisk in front of the branch you are currently on.
Sometimes you may wish to create a new branch _without_ actually
checking it out and switching to it. If so, just use the command
------------
$ git branch <branchname> [startingpoint]
------------
which will simply _create_ the branch, but will not do anything further.
You can then later -- once you decide that you want to actually develop
on that branch -- switch to that branch with a regular 'git switch'
with the branchname as the argument.
Merging two branches
--------------------
One of the ideas of having a branch is that you do some (possibly
experimental) work in it, and eventually merge it back to the main
branch. So assuming you created the above `mybranch` that started out
being the same as the original `master` branch, let's make sure we're in
that branch, and do some work there.