Basic Git Commands List with Example

When we come in the programming developer should know the basic commands of the git. I will fully guide you very effective way.

First of all we should know about git briefly. Git is a software used for control source code also called version control system of your files.

If you think you had developed a software so that should be change consistently according to the business logic for the requirement of client or BA with any risk deleting and updating files or folders. we can track our files which areas we were change since we start a project.

Benefit of usign Git

  • do not worry about you files
  • divided project to the different stages.
  • allow build with muliple developer
  • able to rollback to previous code.
  • tracking project code base.

Git Commands

  1. Always start a project with git initializing command.

`git init`

# Git Branch

ancestor iscreeate branch point

## discard current change on files

`git checkout — <filename>`

## discard current change on folder

`git checkout — <dirname>`

## create new branch derive develpment with -d switch

`git checkout -b <feature> develpment`

## delete branch

`git branch -d <feature>`

## unstage from the already staged files

`git reset <filename>`

## show only commit no other details

`git log –oneline`

## if you need disply only specific number of commit

`git log -1 –oneline`

## get feature and fix bugs

`git log –oneline –grep “^feat\|^fix\|^perf”`

## count total amount of feature commit

`git log –oneline –grep “^feat” | wc -l`

# Git Tags

tagging is creating specific pionts in history(mark release) for repository that can be to restore data)

## git tags show

`git tag`

`git show <tagname>`

`git tag -l “v1.*”`

## git create tag

`git tag <tagname>`

create annotated tate tags

`git tag -a v1.0.0-beta -m “tag for release beta version 1.0.0″`

## git delete tag

`git tag -d <tagname>`

`git tag -delete <tagname>`

delte from the repository as well

`git push origin -d <tagname>`

creeate a branch from a tag and checkout branch

`git checkout -b <branchversionname> <tagversionname>`

create a tag form some post commit (get old version again)

`git tag <tagname> <commit-sha>`

## git push tag

`git push origin <tagname>`

push all the tags

`git push –tags`

Leave a Comment