Git smart! 20 essential tips for Git and GitHub users

The programming world's favorite distributed version control system also lets you find, share, and improve code. Here's how to make Git and GitHub work better for you

While there are dozens of get-started guides for Git and users of GitHub see a "pro tip" every time they refresh GitHub.com, it's still not easy to find a collection of useful tips for developers who want to work smarter with Git and GitHub. Let's fix that.

For those of you who are unfamiliar with Git or GitHub, the next few paragraphs will give you enough background to understand the tips. We'll list about a dozen useful resources at the end of this article.

[ Also on InfoWorld: GitHub's top 10 rock star projects | Bitbucket vs. GitHub: Which project host has the most? | Download the Developers' Survival Guide | Keep up with the latest developer news with InfoWorld's Developer World newsletter. ]

Git is a distributed version control system, originally written by Linus Torvalds in 2005 for and with help from the Linux kernel community. I'm not here to sell you on Git, so I'll spare you the spiel about how fast and small and flexible and popular it is, but you should know that when you clone a Git repository ("repo," for short), you get the entire version history on your own computer, not just a snapshot from one branch at one time.

Git started as a command-line tool, befitting its origin in the Linux kernel community. You can still use the Git command line, if you like, but you don't have to. In particular, if you use GitHub as your host, you can use the free GitHub client on Windows or Mac. On the other hand, the Git command line will work for any host, and it comes pre-installed on most Mac and Linux systems.

Only you can decide whether you are most comfortable using the command line or a native client with a graphical user interface. If you like a GUI, in addition to the GitHub client (Windows and Mac), you might want to consider SourceTree (Windows and Mac, free), TortoiseGit (Windows only, free), and Gitbox (Mac only, $14.99). Or you can use an editor or IDE that supports Git internally (see tip No. 11).

Git/GitHub tip No. 1: Clone almost anything
There are many interesting projects available from GitHub and other public Git repositories that you can clone freely to your own computer. Why would you want to do that? One reason is to learn something about coding style, practice, and tools in a language of interest, including commit log commenting style (see tip No. 4). A second reason is to learn how a given project accomplishes its goals. A third reason, should the licensing both permit you to do so and make sense for your purposes, would be to incorporate the project into your own endeavor or product. Double-check the license, by the way, so that you don't run into compliance issues later on.

The definition of git clone from the manual page:

Clones a repository into a newly created directory, creates remote-tracking branches for each branch in the cloned repository (visible using git branch -r), and creates and checks out an initial branch that is forked from the cloned repository's currently active branch.

After the clone, a plain git fetch without arguments will update all the remote-tracking branches, and a git pull without arguments will in addition merge the remote master branch into the current master branch, if any.

1 2 3 4 5 Page
Mobile Security Insider: iOS vs. Android vs. BlackBerry vs. Windows Phone
Recommended
Join the discussion
Be the first to comment on this article. Our Commenting Policies