Saturday 6 June 2020

Git Basics

Install git client
Set
  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"


Git Handbook:- https://guides.github.com/introduction/git-handbook/
Git Branch & Checkout:- https://www.atlassian.com/git/tutorials/using-branches/git-checkout
Git Merge:- https://www.atlassian.com/git/tutorials/using-branches/git-merge
Undoing Changes:- https://www.atlassian.com/git/tutorials/undoing-changes

Start a new repository and publish it to GitHub

# create a new directory, and initialize it with git-specific functions
git init my-repo

# change into the `my-repo` directory
cd my-repo

# create the first file in the project
touch README.md

# git isn't aware of the file, stage it
git add README.md

# take a snapshot of the staging area
git commit -m "add README to initial commit"

# provide the path for the repository you created on github
git remote add origin https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.git

# push changes to github
git push --set-upstream origin master
$ mkdir src
$ mkdir test
$ mkdir docs
$ touch src/main.py
$ touch test/main.py
$ touch docs/main.md

admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (master)
$ git commit -m "Initial folder structure created."
[master e8bb55f] Initial folder structure created.
 3 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 docs/main.md
 create mode 100644 src/main.py
 create mode 100644 test/main.py

admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (master)
$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 405 bytes | 405.00 KiB/s, done.
Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/pssaur/my-repo.git
   027265e..e8bb55f  master -> master

Create Branch / Create Branch and move the head to branch

$ git branch sprint-1 
$ git checkout sprint-1
$ git checkout -b sprint-2
Switched to a new branch 'sprint-2'
$ git checkout sprint-1
Switched to branch 'sprint-1'

admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (sprint-1)
$ git status
On branch sprint-1
nothing to commit, working tree clean

admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (sprint-1)
$ git branch
  master
* sprint-1
  sprint-2

admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (sprint-1)
$ echo "Sprint 1 Started" >> src/main.py

admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (sprint-1)
$ git status
On branch sprint-1
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:   src/main.py

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

admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (sprint-1)
$ git add .
warning: LF will be replaced by CRLF in src/main.py.
The file will have its original line endings in your working directory

admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (sprint-1)
$ git commit -m "Feature 1 Completed."
[sprint-1 f307660] Feature 1 Completed.
 1 file changed, 1 insertion(+)

admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (sprint-1)
$ echo "Spring 1 Started Testing">> test/main.py

admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (sprint-1)
$ git status
On branch sprint-1
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:   test/main.py

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

admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (sprint-1)
$ git add .
warning: LF will be replaced by CRLF in test/main.py.
The file will have its original line endings in your working directory

admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (sprint-1)
$ git commit -m "Feature 2 Completed"
[sprint-1 5823cc4] Feature 2 Completed
 1 file changed, 1 insertion(+)

admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (sprint-1)
$ git log
commit 5823cc451ab682e2e383334e5300009b483c819d (HEAD -> sprint-1)
Author: Saurabh <ps.sagupta@gmail.com>
Date:   Sat Jun 6 17:16:27 2020 +0530

    Feature 2 Completed

commit f307660e41199b094a8e1cccff49717b4c932014
Author: Saurabh <ps.sagupta@gmail.com>
Date:   Sat Jun 6 17:15:44 2020 +0530

    Feature 1 Completed.

commit e8bb55ffbf762a5dcb7e8bfec9837fa69ecc52c2 (origin/master, sprint-2, master)
Author: Saurabh <ps.sagupta@gmail.com>
Date:   Sat Jun 6 16:13:49 2020 +0530

    Initial folder structure created.

commit 027265e486f1e7ddf1a6e927bcf606fc077057f9
Author: Saurabh <ps.sagupta@gmail.com>
Date:   Sat Jun 6 16:04:38 2020 +0530

    add readme to initial commit

admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (sprint-1)
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (master)
$ cat src/main.py

admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (master)
$ git checkout sprint-1
Switched to branch 'sprint-1'

admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (sprint-1)
$ cat src/main.py
Sprint 1 Started

admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (sprint-1)
$ git push
fatal: The current branch sprint-1 has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin sprint-1


admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (sprint-1)
$ git push --set-upstream origin sprint-1
Enumerating objects: 13, done.
Counting objects: 100% (11/11), done.
Delta compression using up to 4 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (8/8), 676 bytes | 676.00 KiB/s, done.
Total 8 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), done.
remote:
remote: Create a pull request for 'sprint-1' on GitHub by visiting:
remote:      https://github.com/pssaur/my-repo/pull/new/sprint-1
remote:
To https://github.com/pssaur/my-repo.git
 * [new branch]      sprint-1 -> sprint-1
Branch 'sprint-1' set up to track remote branch 'sprint-1' from 'origin'.

admin@DESKTOP-M6VPONK MINGW64 /f/repo/my-repo (sprint-1)
$

Remove file from staging area to working tree 

$ git checkout sprint-2
Switched to branch 'sprint-2'

$ echo "index page initiated..">  index.html

$ git status
On branch sprint-2
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        index.html

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

$ git add .
warning: LF will be replaced by CRLF in index.html.
The file will have its original line endings in your working directory

$ git status
On branch sprint-2
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   index.html


$ git reset index.html

$ git status
On branch sprint-2
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        index.html

nothing added to com

Remove all the changes in staging area and modified changes in working tree. it will not touch the un-track file.

$ git status
On branch sprint-2
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   index.html


$ git reset --hard
HEAD is now at e8bb55f Initial folder structure created.

$ git status
On branch sprint-2
nothing to commit, working tree clean

Remove all the Untracked files from working tree

$ echo "index file code" >> index.html
$ echo "index file code 22222" >> index2.html

$ git status
On branch sprint-2
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        index.html
        index2.html

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

$ git clean -fd .
Removing index.html
Removing index2.html

$ git status
On branch sprint-2
nothing to commit, working tree clean



No comments:

Post a Comment

Jenkins Startup and Configuration

Steps to setup jenkins on ubuntu:- -After installation. check the jenkins services running on not on the server. sudo service jenk...