version control

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.


References

Git

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

GitHub guide‘ on GitHub website is an extensive guide on how to use Git with GitHub.

Semantic versioning

Semantic versioning‘ website contains a set of guidelines to follow when assigning a version number to a code.

Markdown

Mastering Markdown’ on GitHub.

Repository badges

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
git initInitialize repository
git remote add origin <url>Setup new remote URL
git remote -vVerify new remote URL
Clone an existing repositorygit clone <url>
Delete repository

rm -rf .git

Working on a repository

Modify repository files locallygit statusCheck status of files modified in repository

meld <file>

Display changes to a file
git diff <file>
git checkout <file>Discard all changes to a file
git rm <file>Delete file
git reset HEAD <file>Recover deleted file
Add modified files to indexgit add <file1> <file2> <file3>Add specific files
git add .Add all modified files
Commit indexed files to the HEAD

git commit -m "Initial commit"Commit changes with a subject message
git commitCommit changes with a subject and body message
git commit -aAlternatively, add and commit changes with a subject and body message
Push changes to repositorygit push -u origin <branch>

Working on branches

Manage Git branch
git branchList all local branches

git branch <branch>

Create a new branch
git checkout <branch>Switch to newly created branch
git checkout -b <branch>Alternatively, create a new branch and switch to it
Merge modifications in branch to master branch
git checkout masterSwitch to master branch to merge into
git pullUpdate master branch
git diff master <branch>Preview differences in master and current branch before merging
git merge <branch>Merge branch to master
Delete branch
git branch -d <branch>Delete local branch
git push origin --delete <branch>Delete remote branch

Commit history and tags

Commit history
git logShow commit history messages
git log --onelineShow abbreviated commit history
git log --statShow commit statistics
git show -s <commit_SHA_hash>Show message for a specific commit
Tags
git tagList all tags
git tag -d <tag>Delete a specific tag
git tag -a <tag> -m "Version_1.0.0"Create a new annotated tag
git tag -a <tag> <commit_SHA_hash>Create a new annotated tag for a specific commit
git show <tag>Show details of a tag
git checkout <tag>Checkout repository at a specific tag
git push --tagsPush 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:

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *