-
Notifications
You must be signed in to change notification settings - Fork 1
Distribute the code
So far we have worked in our sad little corner, but now that we know the basics, we need to fly with others! We are ready to exchange our code with the whole world!
Except not quite yet, baby steps, baby steps...
Cloning is the usual git way to get code from other people. But not only. You may also clone yourself on your own machine. It can be useful for multi-user machines, when you exchange code on the same host. (git is also clever enough to use hard links and not really copy the whole history if possible, but this is outside the scope of the tutorial)
We will take advantage of this to exchange code with... ourselves.
The syntax is not complicated: git clone followed by the path to the repository. It can be a file system path, or a URL using the http protocol or the git protocol (a binary protocol much faster that the text based http) or finally a classic ssh path (username@host:/path/to/repo). An optional argument is the destination name. Here we use a path and a destination since we will have our two clone in the same directory:
ben@GregoryHouse:~/tmp/testRepo (experimental)$ cd ..
ben@GregoryHouse:~/tmp$ git clone testRepo testRepo-clone
Cloning into 'testRepo-clone'...
done.
ben@GregoryHouse:~/tmp$ cd testRepo-clone
ben@GregoryHouse:~/tmp/testRepo-clone (experimental)$ git status
# On branch experimental
nothing to commit (working directory clean)
ben@GregoryHouse:~/tmp/testRepo-clone (experimental)$ git branch -a
* experimental
remotes/origin/HEAD -> origin/experimental
remotes/origin/alternateHistory
remotes/origin/experimental
remotes/origin/masterHere we used an argument to git branch, -a it show all branches, local and remote, this local repository is aware of. the argument -r show only the ones located in remote repositories. Their name in a path composed of remote/name-of-the remote-repository/nameOfABranchOnThatRepo.
When cloning a repository, the remote location the copy is made from is always called origin. You may get information on it by running this command, very useful when you have several remote repositories (we will talk about that later) or to remind you where this clone comes from:
ben@GregoryHouse:~/tmp/testRepo-clone (experimental)$ git remote show origin
* remote origin
Fetch URL: /home/ben/tmp/testRepo
Push URL: /home/ben/tmp/testRepo
HEAD branch: experimental
Remote branches:
alternateHistory tracked
experimental tracked
master tracked
Local branch configured for 'git pull':
experimental merges with remote experimental
Local ref configured for 'git push':
experimental pushes to experimental (up to date)All the knowledge we have about the remote is there: Path and branches. The Head branch on the remote is experimental, and you will have noticed the local checked out branch was also experimental.
Jump to Pull branches