Git Commands With Output Log

Step by step command only Guide where command starts with symbol $

-----------------------------

  1. git config --global user.name "your username"
  2.  
  3. git config --global user.password "your password"

Track file :

This means the file is added to the git repository in your local machine.

Also called added to the stage area.


Untracked File :

Code is still in your local folder not added to git repository


-----------------------------------------------



Commands

---------------------------


checking current working directory

 rssan@DESKTOP-QA9A7TD MINGW64 ~

$ pwd

/c/Users/rssan


creating a new directory

rssan@DESKTOP-QA9A7TD MINGW64 ~

$ mkdir test


getting inside that newly created directory

rssan@DESKTOP-QA9A7TD MINGW64 ~

$ cd test


creating a new directory inside for git repository

rssan@DESKTOP-QA9A7TD MINGW64 ~/test

$ mkdir repo


getting inside the newly created repo directory

rssan@DESKTOP-QA9A7TD MINGW64 ~/test

$ cd repo/


Again created a mygitrepo directory inside

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo

$ mkdir mygitrepo


getting inside mygitrepo directory

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo

$ cd mygitrepo


Making mygitrepo directory as git repository using init command

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo

$ git init

Initialized empty Git repository in C:/Users/rssan/test/repo/mygitrepo/.git/


rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (master)

$ ls


Again checking current working directory

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (master)

$ pwd

/c/Users/rssan/test/repo/mygitrepo


creating a HTML file inside mygitrepo file

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (master)

$ touch index.html


Creating style.css file inside mygitrepo local folder

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (master)

$ touch style.css


Now checking local folder vs repository ...how many files are there inside git repository

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (master)

$ git status

On branch master


No commits yet


Untracked files:

  (use "git add <file>..." to include in what will be committed)

        index.html

        style.css


nothing added to commit but untracked files present (use "git add" to track)

No files are there in git repository . All are in local folder mygitrepo



Lets add index.html to git repository

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (master)

$ git add index.html


>> now lets check the status

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (master)

$ git status

On branch master


No commits yet


Changes to be committed:

  (use "git rm --cached <file>..." to unstage)

        new file:   index.html


Untracked files:

  (use "git add <file>..." to include in what will be committed)

        style.css

> Yah ! new file index.html is added to git repository as per above log or output



>>Let's remove index.html from repository 

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (master)

$ git rm --cached index.html

rm 'index.html'


>> checking status

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (master)

$ git status

On branch master


No commits yet


Untracked files:

  (use "git add <file>..." to include in what will be committed)

        index.html

        style.css


nothing added to commit but untracked files present (use "git add" to track)

> Nothing added to the repository 


>>Now lets add all files to repository using add. command in a single go

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (master)

$ git add .


>Let's check status

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (master)

$ git status

On branch master


No commits yet


Changes to be committed:

  (use "git rm --cached <file>..." to unstage)

        new file:   index.html

        new file:   style.css

>2 files successfully added...



>>Let's commit the file to git with commit message syntaxed with -m

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (master)

$ git commit -m "file has been commited"

Author identity unknown


*** Please tell me who you are.


Run


  git config --global user.email "you@example.com"

  git config --global user.name "Your Name"


to set your account's default identity.

Omit --global to set the identity only in this repository.


fatal: unable to auto-detect email address (got 'rssan@DESKTOP-QA9A7TD.(none)')


rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (master)

$ ^C


rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (master)

$  git config --global user.email "you@example.com"

>> Error as not mentioned the email id on which it will be committed .So fixed it 

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (master)

$  git config --global user.email "rssandeeprs@gmail.com"


>>Again try and commit with message -m 

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (master)

$ git commit -m "file has been commited"

[master (root-commit) d81e2b7] file has been commited

 2 files changed, 0 insertions(+), 0 deletions(-)

 create mode 100644 index.html

 create mode 100644 style.css


>>Commited

>>Git Log

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (master)

$ git log

commit d81e2b78be66f0211dd5ff267e4e572c5c1079df (HEAD -> master)

Author: Sandeep mishra <rssandeeprs@gmail.com>

Date:   Wed Oct 28 19:13:20 2020 -0700


    file has been committed

> file has been committed 


>>Check branches created

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (master)

$ git branch

* master


>>creating new branch userAuth

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (master)

$ git branch userAuth


>>Again checking all branches

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (master)

$ git branch

* master

  userAuth


>>Switching between branches using the checkout command

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (master)

$ git checkout userAuth

Switched to branch 'userAuth'


>>creating new files inside the newly created branch userAuth

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (userAuth)

$ touch auth.js


>>Editing preexist file using vim editer

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (userAuth)

$ vim index.html

>I updated the content in index.html

>Doesit have updated ? or not let's check... 



>>Again checking git status

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (userAuth)

$ git status

On branch userAuth

Changes not staged for commit:

  (use "git add <file>..." to update what will be committed)

  (use "git restore <file>..." to discard changes in working directory)

        modified:   index.html


Untracked files:

  (use "git add <file>..." to include in what will be committed)

        auth.js


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


rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (userAuth)

$





We edited index.html and add a line <!-- this is a comment -->
Let's check the difference by using diff command


rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (userAuth)
$ git diff index.html
warning: LF will be replaced by CRLF in index.html.
The file will have its original line endings in your working directory
diff --git a/index.html b/index.html
index e69de29..c69c4e1 100644
--- a/index.html
+++ b/index.html
@@ -0,0 +1 @@
+<!-- this is a comment -->

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (userAuth)
$

>>The line is in green color means in previous index.html that line was not there , this time is added.
>>The line is in red means it was there n previous index.html and now it is deleted.





>>Some files we want to ignore check .So the following command

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (userAuth)
$ touch .gitignore

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (userAuth)
$ vim .gitignore

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (userAuth)
$

>put file names in .gitignore using vim edited
>Ex. Device.log


>>But what if 100 of log files generated and we want all to be ignored ...

>>vim edit .gitignore and add the below line

#ignore all files that have a .log extension
*.log
 
>here * means anything with .log extension



>>Now added everything to the repository and committing my work

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (userAuth)
$ git add .
warning: LF will be replaced by CRLF in index.html.
The file will have its original line endings in your working directory
warning: LF will be replaced by CRLF in .gitignore.
The file will have its original line endings in your working directory

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (userAuth)
$ git status
On branch userAuth
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   .gitignore
        new file:   auth.js
        modified:   index.html


rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (userAuth)
$ git commit -m "Add .gitignore"
[userAuth 4193d97] Add .gitignore
 3 files changed, 2 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 auth.js

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygit

>>Now after commit ...

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (userAuth)
$ git status
On branch userAuth
nothing to commit, working tree clean


>>Now the changes we have made all were in userAuth branch. It's time to merge the userAuth branch to the master branch .


So we have to merge everything to master branch .So first switch to master branch and then merge userAuth branch with it.

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (userAuth)
$ git checkout master
Switched to branch 'master'

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (master)
$ git merge userAuth
Updating d81e2b7..4193d97
Fast-forward
 .gitignore | 1 +
 auth.js    | 0
 index.html | 1 +
 3 files changed, 2 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 auth.js

rssan@DESKTOP-QA9A7TD MINGW64 ~/test/repo/mygitrepo (master)
$


>>We use $ git log command to see the history of commits.

Comments

Popular posts from this blog

NumPy Codes and import

Spring container and sequential steps

Deploy your web app to tomcat in war format