Introduction to git and Basic Commands and Creation of repository
Posted By Mohit Shakya | 09-Jan-2017
In this blog we'll discuss about some basic and essential commands of git.
We'll include following commands in this blog:
* About Git
* Install Git (minimal required packages)
* Fetch - getting all assigned branches info from remote
* Branch - identifying current branch
* Pull - get latest codebase on existing branch
* Commit - create a new entry in existing codebase
* Push - upload available modified codebase
* remote add - link to remote repository
* Init - create a new repository
Let's get this started.
What is Git?
It's a version control system, mostly used today for maintain project's version history or we can say it a care taker of our projects codebase in general. It's completely open-source and introduced by Linus Trovald ( the founder of linux ).
Install Git (minimal required packages)
* For Redhat Based Distros:
$ sudo yum install git
* For Debian Based Distros:
$ sudo apt-get install git
*go to link: http://git-scm.com/download/linux
*download binaries and install using guided gui.
Fetch - getting all assigned branches info from remote
To get all assigned branches info from remote git repository ( including all newly assigned or unknown branches ),
use following git command in your local repository:
$ git fetch
Branch - identifying current branch
To identify current working branch, type in your repository:
$ git branch (branch with * sign is your current branch)
Pull - get latest codebase on existing branch
To get all latest codebase on a branch, type:
$ git pull origin <branch_name>
NOTE: be specific to current branch name, if the branch name is not same as the current branch, it would be a 'MERGE' operation.
Commit - create a new entry in existing codebase
To create a new entry in current local repository:
* first, add modified or new files to repository:
$ git add <complete file path one want to add>
$ git add . (to add all availalbe files)
* now, to create them as an entry:
$ git commit -m "<some massage>"
Push - upload available modified codebase
To upload modified codebase use git command in your repository directory:
$ git push origin <current_branch_name>
remote add - link to remote repository
To link current repository to remote repository in your repository directory:
$ git remote add <repository_name> <repository_url>
Init - create a new repository
To create a new repository we use 'git init'.
* Go to directory in console, you want to create repository for.
* type following command:
$ git init
Usage Example: Create a new repository and push to remote repository
$ git init
(create files if directory is empty)
$ git add .
$ git commit -m '<commit_massege>'
$ git remote add <repoName> <repoUrl>
$ git push -u origin master;
Thanks for reading my blog, your comments will be valuable.