If you're a developer who writes code that other developers will use or modify, you should get comfortable with a version control system. The most popular system is Git, and this tutorial explains how to get started with Git using GitHub.
- Developers need an easy way to share files
- Code changes should be tracked
- It should be possible to experiment with changes without breaking it for others
- Git
- Mercurial
- Subversion
- Microsoft Team Foundation Server
This tutorial will focus on Git since it is the most widely-used code-management tool. source
Git allows developers to take "snapshots" of their code. This makes it easy to refer to previous code versions when something breaks, and to test new experimental changes without breaking the existing stable code.
Here is a summary of how this works:
- Create a repository with
git init [project-name]
or clone an existing repository withgit clone [url]
- Add files to the staging area with
git add [file] or git add *
- Commit staged files to the repository with
git commit -m “[message]”
(This requires repository write-access)
To learn more about setting up and using Git, visit https://help.github.com/articles/set-up-git
GitHub is the most widely-used implementation of Git. Interactions with code repositories can all be done via the web browser, and additional functionality is provided by desktop clients compatible with GitHub.
GitHub provides an excellent "Hello World" tutorial that teaches you how to use their platform, but I'll summarize the basics below.
Before you begin: Create a free account at GitHub
Although the GitHub website provides a basic demonstration of Git functionality, it is more practical to install a desktop client if you plan to use Git as part of your daily programming workflow. Here is a partial list of Git-compatible clients:
- Sourcetree (Currently my favorite) | Windows, Mac | Free
- GitHub Desktop | Windows, Mac | Free
- SmartGit | Windows, Mac, Linux | $79/user / Free for non-commercial use
- More clients
This tutorial barely scratches the surface of Git, its GitHub implementation and other version control systems. Here are some additional resources to help you understand code sharing.