http://git.or.cz/course/svn.html#remote
Git - SVN Crash CourseWelcome to the Git version control system! Here we will briefly introduce you to Git usage based on your current Subversion knowledge. You will need the latest Git installed; There is also a potentially useful tutorial in the Git documentation.
How to Read MeIn those small tables, at the left we always list the Git commands for the task, while at the right the corresponding Subversion commands you would use for the job are listed. If you are in hurry, just skimming over them should give you a good idea about the Git usage basics. Before running any command the first time, it's recommended that you
at least quickly skim through its manual page. Many of the commands
have
very useful and interesting features (that we won't list here) and
sometimes
there are some extra notes you might want to know. There's a quick
usage
help available for the Git commands if you pass them the Things You Should KnowThere are couple important concepts it is good to know when starting with Git. If you are in hurry though, you can skip this section and only get back to it when you get seriously confused; it should be possible to pick up with just using your intuition.
CommitingFor the first introduction, let's make your project tracked by Git
and see how we get around to do daily development in it. Let's
Now your tree is officially tracked by Git. You can explore the
That's it. This is one of the more powerful commands. To get a diff with an specific revision and path do:
Git embeds special information in the diffs about adds, removals and mode changes:
That will apply the patch while telling Git about and performing those "meta-changes". There is a more concise representation of changes available:
This will show the concise changes summary as well as list any files that you haven't either ignored or told Git about. In addition, it will also show at the top which branch you are in. While we are at the status command, over time plenty of the
"Untracked files" will get in there, denoting files not tracked by Git.
Wait a moment if you want to add them, run To restore a file from the last revision:
You can restore everything or just specified files. So, just like in SVN, you need to tell Git when you add, move or remove any files:
You can also recursively add/remove whole directories and so on; Git's cool! So, it's about time we commit our changes. Big surprise about the command:
to commit all the changes or, as with Subversion,
you can limit the commit only to specified files
and so on. A few words on the commit message: it is customary
to have a short commit summary as the first line of the message,
because various tools listing commits frequently show only the
first line of the message. You can specify the commit message
using the If you don't pass any And as a bonus, if you pass it the By the way, if you screwed up committing, there's not much you
can do with Subversion, except using some enigmatic BrowsingNow that we have committed some stuff, you might want to review your history:
The log command works quite similar in SVN and Git; again,
The blame command is more powerful as it can detect the movement of
lines,
even with file copies and renames. But there is a
big chance that you probably want to do something different! Usually,
when using annotate you are looking for the origin of some piece of
code, and the so-called pickaxe of Git is much more
comfortable
tool for that job ( You can see the contents of a file, the listing of a directory or a commit with:
Tagging and branchingSubversion marks certain checkpoints in history through copies, the copy is usually placed in a directory named tags. Git tags are much more powerful. The Git tag can have an arbitrary description attached (the first line is special as in the commit case), some people actually store the whole release announcements in the tag descriptions. The identity of the person who tagged is stored (again following the same rules as identity of the committer). You can tag other objects than commits (but that is conceptually rather low-level operation). And the tag can be cryptographically PGP signed to verify the identity (by Git's nature of working, that signature also confirms the validity of the associated revision, its history and tree). So, let's do it:
To list tags and to show the tag message:
Like Subversion, Git can do branches (surprise surprise!). In Subversion, you basically copy your project to a subdirectory. In Git, you tell it, well, to create a branch.
The first command creates a branch, the second command switches
your tree to a certain branch. You can pass an extra argument to
You can list your branches conveniently using the aforementioned
To move your tree to some older revision, use:
or you could create a temporary branch. In Git you can make commits on top of the older revision and use it as another branch. MergingGit supports merging between branches much better than Subversion - history of both branches is preserved over the merges and repeated merges of the same branches are supported out-of-the-box. Make sure you are on one of the to-be-merged branches and merge the other one now:
If changes were made on only one of the branches since the last
merge,
they are simply replayed on your other branch (so-called fast-forward
merge).
If changes were made on both branches, they are merged intelligently
(so-called three-way merge): if any changes conflicted, Aside from merging, sometimes you want to just pick one commit from a different branch. To apply the changes in revision rev and commit them to the current branch use:
Going RemoteSo far, we have neglected that Git is a distributed version control system. It is time for us to set the record straight - let's grab some stuff from remote sites. If you are working on someone else's project, you usually want to clone its repository instead of starting your own. We've already mentioned that at the top of this document:
Now you have the default branch (normally Remote branch, you ask? Well, so far we have worked only with local branches. Remote branches are a mirror image of branches in remote repositories and you don't ever switch to them directly or write to them. Let me repeat - you never mess with remote branches. If you want to switch to a remote branch, you need to create a corresponding local branch which will "track" the remote branch:
You can add more remote branches to a cloned repository, as well as
just
an initialized one, using Now, how do you get any new changes from a remote repository?
You fetch them: Since you frequently just fetch + merge the tracking remote branch, there is a command to automate that:
Sharing the WorkYour local repository can be used by others to pull
changes, but
normally you would have a private repository and a public repository.
The public repository is where everybody pulls and you... do the
opposite? Push your changes? Yes!
We do One important thing is that you should push only to remote branches that are not currently checked out on the other side (for the same reasons you never switch to a remote branch locally)! Otherwise the working copy at the remote branch will get out of date and confusion will ensue. The best way to avoid that is to push only to remote repositories with no working copy at all - so called bare repositories which are commonly used for public access or developers' meeting point - just for exchange of history where a checked out copy would be a waste of space anyway. You can create such a repository. See Setting up a public repository for details. Git can work with the same workflow as Subversion, with a group of
developers
using a single repository for exchange of their work. The only change
is that their changes aren't submitted automatically but they have
to push (however, you can setup a post-commit hook that will push for
you
every time you commit; that loses the flexibility to fix up a screwed
commit, though). The developers must have either an entry in htaccess
(for HTTP DAV) or a UNIX account (for SSH). You can restrict their
shell account only to Git pushing/fetching by using the
You can also exchange patches by mail. Git has very good support
for patches incoming by mail. You can apply them by feeding mailboxes
with patch mails to If you have any questions or problems which are not obvious from the documentation, please contact us at the Git mailing list at [EMAIL PROTECTED]. We hope you enjoy using Git! |
