In this blog we will learn about describing version control, committing source code with git and merging version with git.
What is Version Control System
Version control system is a method or system that organizes various project files and protects modifications to them. We typically use them for code. Version Control System or VCS provides a common central place to store and manage project files, so latest project version is accessible. Git is the common version control system developed by Linus Trovalds, who created Linux operating system. It is a distributed version control system.
There are several components of git. There is a working directory. It is a home subdirectory where all source files are created, modified and reviewed. The staging area is a hidden subdirectory named “.git” . The “.git” directory is created by ‘git init’ command. Working directory source files are registered into this area via ‘git add’ command. Local repository contains each project file’s history and remote repository is typically a cloud-based location.
Some of the popular remote git repositories are:
How to setup local git environment
Now, we will learn about how we will commit changes in version control system like git. To create a local git environment we do following steps:
- We create a working directory
- We initialize the .git/ directory
- We set up local repository options
- Establish your remote repository
Committing source files with Git
For committing source file in git we do following steps:
- We create or modify the source files.
- We add the files to the staging area.
- We commit the files to the local repository and
- We push to files to the remote repository.
Git Configuration Command
Some common git configuration commands are as following:
- git config –global user.name “[FirstName] [LastName]”
Sets a name that is used to identify credits when reviewing version history
- git config –global user.email “[Valid email]”
Sets an email address that will be associated with each history maker
- git config –global color.ui auto
Sets automatic command line coloring for to Git for easy reviewing of changes.
Git Setup Commands
Some of the common git setup commands are as follows:
- git init
Initialize an existing directory as a git repository
- git clone [url]
Retrieve an entire repository from a hosted location via URL
Git Commit Commands
Most used commands while committing the code are listed below:
- git status
Show modified files in working directory, staged for your next commit
- git add [file]
Adds a file as it looks now to your next commit
- Git commit -m [descriptive message]
Commit the staged content as a new commit snapshot
Git Snapshot Command
Some of the most common commands for snapshots management are below:
- git reset [file]
Unstage a file while retaining the changes in working direcotry
- Git diff
Diff of what is change but not staged
- Git diff -staged
Diff of what is staged but not committed.
Git Branch Commands
Some of the most common commands to manage branches and merging them etc. are listed below:
- git branch
List your branches. An * will appear next to the current active branch
- git branch [branch-name]
Create a new branch at the current commit
- git checkout
Switch to another branch and check it out into your working directory
- git merge [branch]
Merge the specified branch’s history into the current one
- git log
Show all commits in the current branch’s history
- We learned about what version control is and what is Git.
- We learned about how to initialize the repository and adding files in it.
- How to modify and commit changes in staging area, local repository and remote repository
- Managing the branches in git