Git is a distributed version control system. This post is helpful to someone who would like to get quickly started with Git. Once up and running with the commands below, the reader is encouraged to follow-up with the comprehensive documentation on Git available from many excellent online sources. This will help to grasp the core concepts of Git, which are essential for regular use.
Note that this post only covers operations on a local repository. Distributed operations like cloning, pulling, pushing etc. will be covered in a future post.
Quick Git Concepts
- Git is fully-functional and self-contained with just a local repository. Committing, branching, merging etc. can all be performed locally with no requirement for a central server.
- Branching and merging are light-weight and extremely fast (local) operations.
- The (hidden) .git directory within the root of working directory is fully self-contained. Git maintains the entire repository that includes information of all of the branches, commits etc. in this single directory.
Initial Setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git config --global user.name "Peter Parker" | |
git config --global user.email peterparker@example.com |
Create A New Repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git init |
Add Files To The Staging Area
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git add [FILENAMES] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git add -A |
Check The Current Status Of The Repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git status |
Commit Staged Files Into The Repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git commit -m ["MESSAGE"] |
Branching And Merging
Branching and merging are extremely light-weight operations in Git. In fact, it is even possible, if required to branch and merge several times a day. The root in Git is known as the Master branch. An important point to note is that only a single branch can be checked-out in the working directory at a given moment.
List All Of The Branches In The Repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git branch |
Create And Switch To A New Branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git checkout -b [BRANCH_NAME] |
Switch To An Existing Branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git checkout [BRANCH_NAME] |
Merging Branches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git merge [SOURCE_BRANCH_NAME] |
Deleting A Branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git branch -d [BRANCH_NAME] |