0% found this document useful (0 votes)
6 views14 pages

Practicals On GITA

This document provides a practical guide on using Git for version control, detailing basic and advanced operations such as initializing a repository, adding files, committing changes, and using pull and push commands with GitHub. It includes installation instructions for both Windows and Ubuntu, as well as steps for creating and managing repositories. Additionally, it covers user configuration, commit history, and the process of forking and deleting repositories on GitHub.

Uploaded by

stashbox45
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)
6 views14 pages

Practicals On GITA

This document provides a practical guide on using Git for version control, detailing basic and advanced operations such as initializing a repository, adding files, committing changes, and using pull and push commands with GitHub. It includes installation instructions for both Windows and Ubuntu, as well as steps for creating and managing repositories. Additionally, it covers user configuration, commit history, and the process of forking and deleting repositories on GitHub.

Uploaded by

stashbox45
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/ 14

Practical 1 -: To perform Version Control using GIT

Git is a free and open source distributed version control system designed to handle everything
from small to very large projects with speed and efficiency. Git is easy to learn and has a tiny
footprint with lightning fast performance. It outclasses SCM tools like Subversion, CVS,
Perforce, and ClearCase with features like cheap local branching, convenient staging areas, and
multiple workflows.
Some of the basic operations in Git are:

1. Initialize
2. Add
3. Commit
4. Pull
5. Push

Some advanced Git operations are:

1. Branching
2. Merging
3. Rebasing

The following diagram depict the all supported operations in GIT

Compiled by Dr. Bhushan Jadhav, TSEC, Contact: 9702868662, Email-: [email protected]


Installation of GIT
1) In windows, download GIT from https://git-scm.com/ and perform the
straightforward installation.
2) In Ubuntu, install GIT using $sudo apt install git, Confirm the version after
installation using command $git –version

Once installation is done, open the terminal in Ubuntu and perform the following steps or in
windows Right click and select Git bash here.

The output of GIT Bash in windows and GIT shell in Ubuntu is shown below

GIT Bash in Windows GIT Shell in Ubuntu

Compiled by Dr. Bhushan Jadhav, TSEC, Contact: 9702868662, Email-: [email protected]


To perform version control, let us create a directory dvcs (Distributed version control system)
and change directory to dvcs.
$ mkdir git-dvcs
$ cd git-dvcs/
Now check the user information using
$ git config –global
As there are no users defined, let us define it using following two commands
$ git config --global user.name "bhushan"
$ git config --global user.email "bhushan,[email protected]"

Now, check the list of users


$ git config --global --list
user.name=bhushan
[email protected]

Let us create a repository for version control named ”git-demo-project”


$ mkdir git-demo-project
$ cd git-demo-project/
Now, initialize the repository using following command
$ git init

The output of above command shown below which adds .git hidden directory in current
repository.

Compiled by Dr. Bhushan Jadhav, TSEC, Contact: 9702868662, Email-: [email protected]


If you have existing repository, then simply delete .git file and reinitialize it.

$ rm -rf .git/

$ git init
Initialized empty Git repository in C:/Users/ADMIN/Desktop/git-dvcs/git-demo-
project/.git/

Now, let us add some files inside our repository “git-demo-project”

To add files in the repository by create or copy some doc,html,image files inside
current directory to see index and staging area. The add command is used along with
dot (. Dot means current directory) for adding files in current repository i.e. making
them in staging mode. They are untracked until we commit them.

$ git add .
Index and staging area
To check the status of repository, use
$ git status
Which will show you some untrack files, so untracks files can be tracked using commit
command.

Now, let us commit the changes


$ git commit -m "First Commit" (#here -m for message)

Add index.html in our directory

Compiled by Dr. Bhushan Jadhav, TSEC, Contact: 9702868662, Email-: [email protected]


$ git add .
$ git commit -am "express Commit" (#Here -a used for express commit)
$ nano index.html

$ touch teststatus

Changes are Discarded by checkout

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


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

Compiled by Dr. Bhushan Jadhav, TSEC, Contact: 9702868662, Email-: [email protected]


$ git add index.html
$ git add teststatus

$ git commit -am "Express commit"

Now let us see history of commits. The log command is used for seeing the commit history.

$ git log

Compiled by Dr. Bhushan Jadhav, TSEC, Contact: 9702868662, Email-: [email protected]


To see all the operation in oneline use the –-oneline option in log command

–-oneline option for particular file in log command

Example 2: Performing Version control in GITHUB with Pull and Push commands

First open Github.com and create a new account.After verifying account through E-mail, create a
Repository on github.com.

Open github.com→ create an account→After login Select New repository from the menu.

Compiled by Dr. Bhushan Jadhav, TSEC, Contact: 9702868662, Email-: [email protected]


Now Specify a Name to repository and select public option followed by create repository

Compiled by Dr. Bhushan Jadhav, TSEC, Contact: 9702868662, Email-: [email protected]


By default, we can create public repository in Github. So we can copy the entire public
repository of any other users in to own account using “FORK” Operation. Now fork the
repository (Sharing with other users who wants to contribute).

Login with another account→Copy and Paste URL of repository→then just click on fork to
clone to others account. Suppose we want to fork public repository “timetracker”. So search for
“timetracker” github repository on google and once its opened clicked on “Fork button” from the
top of the github web page as shown below.

After fork it will be added in your local repository.

Compiled by Dr. Bhushan Jadhav, TSEC, Contact: 9702868662, Email-: [email protected]


To delete the repository, open the desired repository you want to delete and go to the settings
option. There you will see delete repository button to delete it.

Now, if you want to download a repository in local machine, then git clone command is used
followed by path to repository. In GitHub the path of repository can be known through clone or
download button and it can be downloaded using git clone command as shown below.

Compiled by Dr. Bhushan Jadhav, TSEC, Contact: 9702868662, Email-: [email protected]


Pull and Push Processes

The pull command used to fetch the repository from github to local while push is used to commit files
from local repository to Github.

Push → Push changes to Web repository

Pull → Pull changes to Local repository

The following commands are used for pull and push repositories

A) Push command

$ git remote add origin https://github.com/bhushanjadhav1/siesworkshop.git


$ git remote show origin

Compiled by Dr. Bhushan Jadhav, TSEC, Contact: 9702868662, Email-: [email protected]


If you add remote again then will show you fatal error.
$ git remote add origin https://github.com/bhushanjadhav1/Myrepository.git
fatal: remote origin already exists.
So, to delete origin rm origin command is used
$ git remote rm origin
Now, to push the local repository to remote github following command is used
$ git push -u origin master

Now you can check the github for updated contents.

B) Pull Changes

Compiled by Dr. Bhushan Jadhav, TSEC, Contact: 9702868662, Email-: [email protected]


Pull command is used to download the remote updated repository into local one. The
command for download is

$ git pull

Now you can see the changes in local repository using git log.

C) Fetch
Suppose you have a file in github and you have changes that.

ORIGINAL FILE

Changed File

Compiled by Dr. Bhushan Jadhav, TSEC, Contact: 9702868662, Email-: [email protected]


Now we use fetch command to fetch the changes, which will show you both the files like
original and changed in local repository.
$ git fetch

Here fetch will not show you like updated changes file as like push. So use merge
command to merge the changes so use following command for merge.
$ git merge origin/master

Online Resource: https://dzone.com/articles/top-20-git-commands-with-examples

Compiled by Dr. Bhushan Jadhav, TSEC, Contact: 9702868662, Email-: [email protected]

You might also like