Tuesday 20 February 2018

Git bash basic commands for online visual studio project

what is Git ?

  1. Version Control.
  2. Distributed version control system.
  3. Flexible
  4. Simultaneous development
  5. Faster releases
  6. Strong community support


  1. Branches
  2. Files and commits
  3. Pull requests
  4. Merge Branches


Git BASH : Command line utility for suite for both window and LINUX.
Git GUI : For Windows users having GUI, it is alternative to Git BASH.
Shell Integration:  Integrated with Win folder where we can simply right-click and play with the integrated BASH or GUI options.

For windows Install Git from  https://git-scm.com/download/win

Basic Commands

$ help
GNU bash, version 4.3.46(2)-release (x86_64-pc-msys)
These shell commands are defined internally.  Type `help' to see this list.
Type `help name' to find out more about the function `name'.
Use `info bash' to find out more about the shell in general.
Use `man -k' or `info' to find out more about commands not in this list.

$ git status
fatal: Not a git repository (or any of the parent directories): .git

$ git init
Initialized empty Git repository in D:/Raj kumar/Work/Code/.git/

Cloning into 'OTest'…

Go to rajdev.visualstudio.com
> Project
> Code
> Clone (right side)
> generate git credentials

Cloning into 'OTest'…
remote:                    vSTs
remote:                  vSTSVSTSv
remote:                vSTSVSTSVST
remote: VSTS         vSTSVSTSVSTSV
remote: VS  tSVSTSVSTSv      STSVS
remote: VS   tSVSTSVST       SVSTS
remote: VSTSv        STSVSTSVSTSVS
remote:                VSTSVSTSVST
remote:                  VSTSVSTs
remote:                    VSTs    (TM)
remote:  Microsoft (R) Visual Studio (R) Team Services
Receiving objects: 100% (399/399), 14.86 MiB | 1.14 MiB/s, done.
Resolving deltas: 100% (312/312), done.


$ git branch
* master

$ git show-branch --all
* [master] Initial commit from SVN Repo
 ! [origin/HEAD] Initial commit from SVN Repo
  ! [origin/MC885] Added new columns & fields
   ! [origin/master] Initial commit from SVN Repo
  +  [origin/MC6885] Added new columns & fields
*+++ [master] Initial commit from SVN Repo

$ git show-branch --remotes
! [origin/HEAD] Initial commit from SVN Repo
 ! [origin/MC6885] Added new columns & fields
  ! [origin/master] Initial commit from SVN Repo
 +  [origin/MC6885] Added new columns & fields
+++ [origin/HEAD] Initial commit from SVN Repo

$ git checkout MC6885
Switched to branch 'MC6885'
Help, Checkout is for switching between branches in a repository you already have. $ git checkout -b MC6886, -b is used to create a new branch if you don't have.

$ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 2 and 13 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)
nothing to commit, working tree clean
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)
Changes to be committed:
        modified:   ….
        modified:   ..
        modified:   ….
Unmerged paths:
  (use "git add <file>..." to mark resolution)

$ git reset --hard
HEAD is now at 2bf2325 Purpose of Creating 2bf2325.

$ git gc
$ git gc --force
Counting objects: 11562, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (8866/8866), done.
Writing objects: 100% (11562/11562), done.
Total 11562 (delta 6669), reused 7519 (delta 2669)

$ git pull
 * [new branch]      MC1692          -> origin/MC1692
 * [new branch]      MC3635-continue -> origin/MC3635-continue
   d7d3a30..ba39b  Raj           -> origin/raj
Updating 10ffef7..4266be2

Available more commits (12/12) in local master. And in remote master permission denied for direct checkin.
$ git log
$ git reset --hard
$ git reset --hard 34c5fdfsdfsdfsdfsdf4fe51e935aa63e32619cd
$ git pull
$ git push

Fetch latest changes git fetch origin/master
Discard any local changes git reset --hard origin/master
Replay latest changes from master git rebase origin/master
Replay your work in progress git rebase origin/work-in-progress
Sync your work in progress with latest master git rebase origin/master

On branch master
Your branch is behind 'origin/master' by 18 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
$ git reset --hard HEAD~1
HEAD is now at 9359f455 Merged PR 7795: Fix the issue of getting nulls

If you are running $ git pull and you are getting this error:
Your local changes to the following files would be overwritten by merge:
Please commit your changes or stash them before you merge.
Updating 6fc17b12128f

$ git checkout origin/master -f
Note: checking out 'origin/master'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

Verify status again
$ git status
HEAD detached at origin/master
nothing to commit, working tree clean

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   dbObjects/.....
        modified:   dbObjects/........

no changes added to commit (use "git add" and/or "git commit -a")

  • $ git rm .gitattributes
  • $ git add -A
  • $ git reset --hard
  • $ git status

On branch master
Your branch is up to date with 'origin/master'.