Git Basics

Now a days Git is something what everybody heard in the field of IT. Its all because cloud computing provides very relevant environment to perform or follow the DevOps culture and Git is a big part of it

Git is a distributed Version Control system for tracking changes in the source code during software development.

Git is open source and designed to handle everything from small to very large projects with speed and agility. It gives programmers a hassle free environment because of branching system what that means that people can create there branch out of the master branch and work on it rather messing around the master code.

Lets see the basic commands of Git that would help you work on this part of SCM "software configuration management"


git config 

This command used to set the user name and email address of author to the commits .e.g

git config --global user.name "Pachehra"
git config --global user.email "cloud.pachehra@gmail.com"

Now you have set the user name and email address & you want to check what user name and email associated with the session you can check by below commands -

git config --global user.name
git config --global user.email


git init

This command used to initiate the git repository or after running this command you can find .git folder in the repository.



git clone

This command used to clone the existing project with the help of URL .e.g

git clone https://github.com/Pachehra/gittest.git


git add

This command adds the file on the staging area or git starts tracking once you add the files.

git add <name of file for single file>
git add --a <for all the fine inside the folder>
git add *  <add all the file in staging>


git commit 

This command is the one which snapshot the file permanently in the version history.

git commit -m "<type message>" (for one file commit)   
git commit -a -m "type message"  (to commit all files in staging area or changed after adding in stage)


git diff

this command shows the file differences which are not yet staged means only the modified part of the file not the count to get the output you need to track or add file once.


git diff --staged

this command shows difference between staged and committed files.


git diff  <branch_1>  <branch_2>

this command will help to find the difference in the files of 2 branches.


git reset 

this command will reset the tree everything from staging area to untracked area and you cam also use commit id to reset the committed branch.

git reset  <commit id >


git status

this command that we use quite often and it list all the files which are not tracked or are in staging area or any modified file after staged.


git rm 

this command deletes or removes file from working directory and stages the deletion. Once you run the git rm command file gets remove & if you run git status you can see deleted file in stage area.


git log 

this command is used to list the version history for the current branch.


git log -follow  <file name>

this command can give you history commit of particular file.


git show <commit id>

this would show the metadata and content changes of the specified commit.


git tag  <commit id>

this command is to give tag to the specified comit.


git branch

This is to list all the local branches in the current repository.


git branch <name for branch>

this is to create new branch


git branch  -d <branch name>

this will delete the branch specified


git checkout

this will help you to switch between the branches .e.g

git checkout <branchname>
git checkout -b  <branchname>  creates branch and switch as well


git merge 

this will you merge your branch history to the current branch & merge made by recursive strategy.


git remote 

this would connect your local repository to the remote repo.


git push

this will push the committed changes to the remote repository.

git push < variable name >  <branch>  .e.g   git push origin master 
git push -all <variable name>    .e.g   git push  --all origin  
git push  <variable name > : <branch>  .e.g   git push  origin : branch


git pull 

this will fetch and merges changes on the remote server to your working directory
git pull https://github.com/Pachehra/gittest.git


git stash save

this will temporarily stash all modified tracked files


git stash pop

this will restore the most recently stashed files.


git stash drop 

this will discard most recently stashed change-set










1 comment:

  1. Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing.
    DevOps Training
    DevOps Online Training
    DevOps Training in Ameerpet

    ReplyDelete

Azure DevOps

Azure DevOps is a suite of development tools provided by Microsoft, designed to support the entire development lifecycle of a software proje...