Git is a free and open source Version Control System (VCS) widely used by software developers these days. It came into existence in 2005 as an alternative to BitKeeper (distributed VCS) through the efforts of Linus Torvalds, creator of the Linux kernel. Some of the objectives while developing this new system were simplicity, speed, non-linear code development and ability of handle large projects. Over the years Git has matured and gained significant popularity while adhering to its initial objectives.
For a newbie, learning Git might seem an intimidating task at first. However, with a small amount of knowledge and a little bit of practice, one can quickly start taking advantage of the numerous features that it has to offer. One of the major web based hosting services for Git is GitHub. After being founded in 2008, it gained popularity rapidly making it now the largest host of source code in the world.
In this blog I have compiled a list of useful material which will get a beginner familiarized with Git and GitHub.
- Useful Git commands
- Guidelines for commit messages
‘Git simple guide‘ by Roger Dudler is an easy to understand illustrative guide outlining the basics of Git. If one is completely unfamiliar with Git then this guide may be a good starting point.
‘Git and GitHub guide‘ by Benjamin A.
‘How to undo anything with Git‘ by Joshua Wehner describes a set of useful git commands to undo changes in Git.
‘Git cheat sheet‘ by Nina Jaeschke.
|‘ProGit‘ is a book by Scott Chacon and Ben Straub which extensively details various aspects of Git.|
‘GitHub guide‘ on GitHub website is an extensive guide on how to use Git with GitHub.
‘Semantic versioning‘ website contains a set of guidelines to follow when assigning a version number to a code.
‘Mastering Markdown’ on GitHub.
‘Shield.io‘ website contains comprehensive material on creation of badges for repositories
‘Badges in Markdown‘ by Lilian Besson.
‘Repository badges‘ lists some useful repository badges with detailed description.
Useful Git commands
Working on a Git repository can become challenging for beginners specially when it comes to usage of Git commands. This section lists some Git commands which one might frequently use.
Create, clone and delete repositories
|Create repository from scratch||Initialize repository|
|Setup new remote URL|
|Verify new remote URL|
|Clone an existing repository|
Working on a repository
|Modify repository files locally||Check status of files modified in repository|
|Display changes to a file|
|Discard all changes to a file|
|Recover deleted file|
|Add modified files to index||Add specific files|
|Add all modified files|
|Commit indexed files to the HEAD||Commit changes with a subject message|
|Commit changes with a subject and body message|
|Alternatively, add and commit changes with a subject and body message|
|Push changes to repository|
Working on branches
|Manage Git branch||List all local branches|
|Create a new branch|
|Switch to newly created branch|
|Alternatively, create a new branch and switch to it|
|Merge modifications in branch to master branch||Switch to master branch to merge into|
|Update master branch|
|Preview differences in master and current branch before merging|
|Merge branch to master|
|Delete branch||Delete local branch|
|Delete remote branch|
Commit history and tags
|Commit history||Show commit history messages|
|Show abbreviated commit history|
|Show commit statistics|
|Show message for a specific commit|
|Tags||List all tags|
|Delete a specific tag|
|Create a new annotated tag|
|Create a new annotated tag for a specific commit|
|Show details of a tag|
|Checkout repository at a specific tag|
|Push tags to repository|
Guidelines for commit messages
Writing meaningful commit messages is essential when working on a collaborative project. Ideally, the commit message should summarize the essence of the changes made to the code in the most concise manner.
Following is a list of guidelines recommended for a commit message:
- Limit the subject to 50 characters.
- Use uppercase format for subject.
- Don’t end the subject with a period.
- Use imperative style in subject.
Frequently used commit messages that I prefer are often along these lines:
- Refactor code
- Change code format style
- Remove unused code
- Improve code design and readability
Recommended reading on Git commit messages:
- Udacity Git commit message style guide.
- “Git commit messages” on Karma.
- Blog on “Creating a longer commit message” by Haydar Ali Ismail.