Ok, after seeing this post by PJ Hyett, I have decided to skip to the end and go with Git.
So what I need is a beginner's practical guide to Git. "Beginner" being defined as someone who knows how to handle their compiler, understands to some level what a Makefile is, and has touched source control without understanding it very well.
"Practical" being defined as this person doesn't want to get into great detail regarding what Git is doing in the background, and doesn't even care (or know) that it's distributed. Your answers might hint at the possibilities, but try to aim for the beginner that wants to keep a 'main' repository on a 'server' which is backed up and secure, and treat their local repository as merely a 'client' resource.
So:
Installation/Setup
- How to install Git
- How do you set up Git? Try to cover Linux, Windows, Mac, think 'client/server' mindset.
- How do you create a new project/repository?
- How do you configure it to ignore files (.obj, .user, etc) that are not really part of the codebase?
Working with the code
- How do you get the latest code?
- How do you check out code?
- How do you commit changes?
- How do you see what's uncommitted, or the status of your current codebase?
- How do you destroy unwanted commits?
- How do you compare two revisions of a file, or your current file and a previous revision?
- How do you see the history of revisions to a file?
- How do you handle binary files (visio docs, for instance, or compiler environments)?
- How do you merge files changed at the "same time"?
- How do you undo (revert or reset) a commit?
Tagging, branching, releases, baselines
- How do you 'mark' 'tag' or 'release' a particular set of revisions for a particular set of files so you can always pull that one later?
- How do you pull a particular 'release'?
- How do you branch?
- How do you merge branches?
- How do you resolve conflicts and complete the merge?
- How do you merge parts of one branch into another branch?
- What is rebasing?
- How do I track remote branches?
- How can I create a branch on a remote repository?
- How do I delete a branch on a remote repository?
- Git workflow examples
Other
- Describe and link to a good GUI, IDE plugin, etc. that makes Git a non-command line resource, but please list its limitations as well as its good.
- msysgit - Cross platform, included with Git
- gitk - Cross platform history viewer, included with Git
- gitnub - Mac OS X
- gitx - Mac OS X history viewer
- smartgit - Cross platform, commercial, beta
- tig - console GUI for Linux
- qgit - GUI for Windows, Linux
- Git Extensions - package for Windows, includes friendly GUI
- Any other common tasks a beginner should know?
- How do I work effectively with a subversion repository set as my source control source?
Other Git beginner's references
- Git guide
- Git book
- Git magic
- gitcasts
- GitHub guides
- Git tutorial
- Progit - book by Scott Chacon
- Git - SVN Crash Course
- Git from the bottom up
- Git ready
- gitref.org
- Git visual cheatsheet
Delving into Git
I will go through the entries from time to time and 'tidy' them up so they have a consistent look/feel and it's easy to scan the list - feel free to follow a simple "header - brief explanation - list of instructions - gotchas and extra info" template. I'll also link to the entries from the bullet list above so it's easy to find them later.
How do you create a new project/repository?
A git repository is simply a directory containing a special
.git
directory.This is different from "centralised" version-control systems (like subversion), where a "repository" is hosted on a remote server, which you
checkout
into a "working copy" directory. With git, your working copy is the repository.Simply run
git init
in the directory which contains the files you wish to track.For example,
This creates a
.git
(hidden) folder in the current directory.To make a new project, run
git init
with an additional argument (the name of the directory to be created):To check if the current current path is within a git repository, simply run
git status
- if it's not a repository, it will report "fatal: Not a git repository"You could also list the
.git
directory, and check it contains files/directories similar to the following:If for whatever reason you wish to "de-git" a repository (you wish to stop using git to track that project). Simply remove the
.git
directory at the base level of the repository.Caution: This will destroy all revision history, all your tags, everything git has done. It will not touch the "current" files (the files you can currently see), but previous changes, deleted files and so on will be unrecoverable!
Git Magic is all you'll ever need. Guaranteed or your money back!
How do you see the history of revisions to a file?
How do you branch?
The default branch in a git repository is called
master
.To create a new branch use
To see a list of all branches in the current repository type
If you want to switch to another branch you can use
To create a new branch and switch to it in one step
To delete a branch, use
To create a branch with the changes from the current branch, do
git status
is your friend, use it often. Good for answering questions like:Unlike, say
svn status
,git status
runs nigh-instantly even on large projects. I often found it reassuring while learning git to use it frequently, to make sure my mental model of what was going on was accurate. Now I mostly just use it to remind myself what I've changed since my last commit.Obviously, it's much more useful if your .gitignore is sanely configured.
Why yet another howto? There are really good ones on the net, like the git guide which is perfect to begin. It has good links including the git book to which one can contribute (hosted on git hub) and which is perfect for this collective task.
On stackoverflow, I would really prefer to see your favorite tricks !
Mine, which I discovered only lately, is
git stash
, explained here, which enables you to save your current job and go to another branchEDIT: as the previous post, if you really prefer stackoverlow format with posts as a wiki I will delete this answer