Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
3 views9 pages

Ex 2 Git VCS

Uploaded by

hemnathit302
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views9 pages

Ex 2 Git VCS

Uploaded by

hemnathit302
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

EX: NO: 2 VERSION CONTROL SYSTEM

DATE:

Aim:
To use version control systems command to clone, commit, push, fetch, pull,
checkout, reset, and delete repositories.

Description:
Git is currently the most popular implementation of a distributed version control
system. Git originates from the Linux kernel development and was founded in 2005
by Linus Torvalds. Nowadays it is used by many popular open source projects, e.g.,
the Android or the Eclipse developer teams, as well as many commercial
organizations. A version control system (VCS) allows you to track the history of a
collection of files.
It supports creating different versions of this collection. Each version captures a
snapshot of the files at a certain point in time and the VCS allow you to switch
between these versions. These versions are stored in a specific place, typically
called a repository. The figure below shows the processing of files.

Version Control System Processing


Procedure:
Step 1: Download & Install
You need to setup Git on your local machine, as follows:
http://git- scm.com/downloads
. For Ubuntu, issue command "sudo apt-get install
git".

Step 2: Install the File from downloads (GNU: General Public License will be installed)

Step 3: Select location to install Git.

Step 4: Select shortcut icons to display in Desktop and choose default editor.

Step 5: Select Git from bash only and then open SSL library. Now the Git bash will be
installed and launched successfully in local machine.

Step 6: Set up your username and email (Customization)


$git config --global user.name "fosslab"

$ git config --global user.email "[email protected]"


Step 7: $git config --list
pack.packsizelimit=2g
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=openssl
http.sslcainfo=C:/Program Files/Git/mingw32/ssl/certs/ca-bundle.crt
core.autocrlf=true
core.fscache=true
core.symlinks=false
pull.rebase=false
credential.helper=manager-core
credential.https://dev.azure.com.usehttppath=true
init.defaultbranch=master
user.name=fosslab
[email protected]

The figure below shows the tracking procedure of files.

File Tracking Process

Step 8: Setup the Working Directory for a New Project


SUBHI@KINGSTON MINGW32 ~
$ mkdir JavaProgram

$ cd JavaProgram/

$ vi Hello.java
import java.io.*;
public class Hello
{
public static void main(String args[])
{
System.out.println("Git - VCS");
}
}

$ export PATH=$PATH:"C:\Program Files\Java\jdk1.6.0_24\bin"


$ javac Hello.java
SUBHI@KINGSTON MINGW32 ~/JavaProgram
$ java Hello
Git VCS
// Initialize Git repo for this project
$ git init
Initialized empty Git repository in C:/Users/SUBI/JavaProgram/.git/

$ ls -al
total 18
drwxr-xr-x 1 SUBHI 197121 0 Dec 30 20:42 ./
drwxr-xr-x 1 SUBHI 197121 0 Dec 30 20:39 ../
drwxr-xr-x 1 SUBHI 197121 0 Dec 30 20:42 .git/
-rw-r--r-- 1 SUBHI 197121 413 Dec 30 20:41 Hello.class
-rw-r--r-- 1 SUBHI 197121 122 Dec 30 20:39 Hello.java

// Staging File Changes for Tracking


$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
Hello.class
Hello.java
nothing added to commit but untracked files present (use "git add" to track)

$ git add *.java


warning: LF will be replaced by CRLF in Hello.java.
The file will have its original line endings in your working directory

SUBHI@KINGSTON MINGW32 ~/JavaProgram (master)


$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: Hello.java
Untracked files:
(use "git add <file>..." to include in what will be committed)
Hello.class

// Committing File Changes (git commit)


$ git commit -m "First commit"
[master (root-commit) 5b1fcbf] First commit
1 file changed, 8 insertions(+)
create mode 100644 Hello.java

SUBHI@KINGSTON MINGW32 ~/JavaProgram (master)


$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
Hello.class

nothing added to commit but untracked files present (use "git add" to track)
// Viewing the Commit Data
$ git log
commit 5b1fcbfb58ef3eab535df2deabdf3ed7fa288ccc (HEAD -> master)
Author: fosslab <[email protected]>
Date: Thu Dec 30 20:48:24 2021 +0530

First commit

SUBHI@KINGSTON MINGW32 ~/JavaProgram (master)


$ git log --stat
commit 5b1fcbfb58ef3eab535df2deabdf3ed7fa288ccc (HEAD -> master)
Author: fosslab <[email protected]>
Date: Thu Dec 30 20:48:24 2021 +0530
First commit
Hello.java | 8 ++++++++
1 file changed, 8 insertions(+)

$ vi Hello.java
import java.io.*;
public class Hello
{
public static void main(String args[])
{
System.out.println("Git - VCS");
System.out.println("After First Commit");
}
}

$ git status
On branch master
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: Hello.java
Untracked files:
(use "git add <file>..." to include in what will be committed)
Hello.class
no changes added to commit (use "git add" and/or "git commit -a")

SUBHI@KINGSTON MINGW32 ~/JavaProgram (master)


$ git diff
warning: LF will be replaced by CRLF in Hello.java.
The file will have its original line endings in your working directory
diff --git a/Hello.java b/Hello.java
index cd2eb4b..2202d7e 100644
--- a/Hello.java
+++ b/Hello.java
@@ -4,5 +4,6 @@ public class Hello
public static void main(String args[])
{
System.out.println("Git - VCS");
+ System.out.println("After First Commit");
}
}
$ git add Hello.class

SUBHI@KINGSTON MINGW32 ~/JavaProgram (master)


$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: Hello.class

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: Hello.java

SUBHI@KINGSTON MINGW32 ~/JavaProgram (master)


$ git diff
warning: LF will be replaced by CRLF in Hello.java.
The file will have its original line endings in your working directory
diff --git a/Hello.java b/Hello.java
index cd2eb4b..2202d7e 100644
--- a/Hello.java
+++ b/Hello.java
@@ -4,5 +4,6 @@ public class Hello
public static void main(String args[])
{
System.out.println("Git - VCS");
+ System.out.println("After First Commit");
}
}

$ git diff --staged


diff --git a/Hello.class b/Hello.class
new file mode 100644
index 0000000..179f0e7
Binary files /dev/null and b/Hello.class differ

SUBHI@KINGSTON MINGW32 ~/JavaProgram (master)


$ git commit -m "Second Commit"
[master f31aa05] Second Commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 Hello.class

SUBHI@KINGSTON MINGW32 ~/JavaProgram (master)


$ git status
On branch master
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: Hello.java

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

Sign up for a GIT host, such as Github https://github.com/signup/free (Unlimited


for public projects; fee for private projects)

Login to the github.com

Create a new remote repo called "test".

On your local repo (let's continue to work on our "hello-git" project), set up the
remote repo's name and URL via "git remote add <remote-name> <remote- url>"
command.

By convention, we shall name our remote repo as "origin". You can find the URL of a
remote repo from the Git host. The URL may take the form of HTTPS or SSH. Use HTTPS
for simplicity.
https://github.com/chengathirmurugesan/test.git
origin https://github.com/fosslab/test.git (fetch)
origin https://github.com/fosslab/test1.git (push)

You can list all the remote names and their corresponding URLs via
"git remote -v"

Here you tried to push your repo to GitHub. But before that fetch the metadata
from GitHub.
// fetch the data from GitHub
$ git fetch
warning : no common commits remote : Enumerating Objects:4,done
remote: Counting objects:100% (4/4),done
remote: Compressing objects: 100% (3/3) done
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0 unpacking
objects:100% (4/4),12.48 KiB |45.00 KiB/s,done
From https://github.com/fosslabn/test.git
* [new branch] master -> origin/master

Push the commits from the local repo to the remote repo via
"git push -u <remote-name> <local-branch-name>".

$ git push origin master --force


Username for 'https://github.com': [email protected]
Password for 'https://[email protected]': *******
Counting objects: 8, done.
Delta compression using up to 8 threads. Compressing objects: 100% (8/8), done.
Writing objects: 100% (8/8), 1.13 KiB | 0 bytes/s, done.
Total 10 (delta 1), reused 0 (delta 0)
To https://github.com/your-username/test.git
[new branch] master -> master
Branch master set up to track remote branch master from origin.

Login to the GIT host and select the remote repo "test", you shall find all the
committed files.
Push the commits on Local Master Branch to remote

$ git push origin master


Username for 'https://github.com': ******
Password for 'https://[email protected]': ******
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 377 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To https://github.com/your-username/test.git
711ef4f..744307e master -> master

Login to the GIT host and select the remote repo "test", you shall find all the
committed files -

// Cloning a Project from a Remote Repo

git clone <remote-url>


// <url>: can be https (recommended), ssh or file.
// Clone the project UNDER the current directory
// The name of the "working directory" is the same as the remote project name

$ git clone <remote-url> <working-directory-name>


// Clone UNDER current directory, use the given "working directory" name

$ git clone https://github.com/fosslab/test1.git hello-git-cloned


Cloning into 'hello-git-cloned'...
remote: Counting objects: 13, done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 13 (delta 2), reused 13 (delta 2)
Unpacking objects: 100% (13/13), done.
Checking connectivity... done.

//Verify the Cloned git hub repository


$ cd hello-git-cloned

//Using ls a command check the Directory


$ ls -a
Hello.java Hello.class

//Check the status of Git Hub


$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

The "git clone" automatically creates a remote name called "origin" mapped to the
cloned remote-URL. You can check via "git remote -v":
Summary of Basic "Edit/Stage/Commit/Push" Cycle
$ git add <file> // for new and modified files
$ git rm <file> // for deleted files
$ git mv <old-file-name> <new-file-name> // for renamed file

// Commit (ALL staged file changes)


$ git commit -m "message"

// Push
$ git push <remote-name> <local-branch-name>

// Check Out
For example, let's create a Git-managed project called git_branch_test with only the
a single-line README.txt file:

$ vi README.txt
Welcome to VCS
Git Hub Repository

$ git init
Reinitialized existing Git repository in C:/Users/SUBI/JavaProgram/.git/

$ git add README.txt


warning: LF will be replaced by CRLF in README.txt.
The file will have its original line endings in your working directory

$ git commit -m "Commit 1"


[master fed9637] Commit 1
1 file changed, 3 insertions(+)
create mode 100644 README.txt

// Append a line in README.txt:


$ vi README.txt
Welcome to VCS
Git Hub Repository
Remote Repository

$ git status
On branch master
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: Hello.java
modified: README.txt
no changes added to commit (use "git add" and/or "git commit -a")

$ git add README.txt


warning: LF will be replaced by CRLF in README.txt.
The file will have its original line endings in your working directory

$ git commit -m "Commit 2"


[master a25ff44] Commit 2
1 file changed, 1 insertion(+), 1 deletion(-)
// Show all the commits (one line each)
$ git log --oneline
a25ff44 (HEAD -> master) Commit 2
fed9637 Commit 1
f31aa05 Second Commit
5b1fcbf First commit

//create a branch
$ git branch level

SUBHI@KINGSTON MINGW32 ~/JavaProgram (master)


$ git checkout level
Switched to branch 'level'
M Hello.java

$ git status
On branch level
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: Hello.java
no changes added to commit (use "git add" and/or "git commit -a")

$ git commit -m "Commit 3"


On branch level
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: Hello.java
no changes added to commit (use "git add" and/or "git commit -a")

$ git checkout master


Switched to branch 'master'
M Hello.java

$ git status
On branch master
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: Hello.java

$ git log --oneline


a25ff44 (HEAD -> master, level) Commit 2
fed9637 Commit 1
f31aa05 Second Commit
5b1fcbf First commit

RESULT:
Thus the procedure to use GIT version control systems command to clone,
commit, push, fetch, pull, checkout, reset, and delete repositories was successfully
implemented.

You might also like