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

Experiment No. 2

The document outlines an experiment focused on creating and forking repositories in GitHub as part of a DevOps lab. It includes steps for creating a GitHub account, synchronizing repositories, tagging commits, and reverting changes, along with objectives and outcomes for students. Additionally, it provides hardware/software requirements, theory, and references for further reading on version control systems.

Uploaded by

aahilgazali102
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 views8 pages

Experiment No. 2

The document outlines an experiment focused on creating and forking repositories in GitHub as part of a DevOps lab. It includes steps for creating a GitHub account, synchronizing repositories, tagging commits, and reverting changes, along with objectives and outcomes for students. Additionally, it provides hardware/software requirements, theory, and references for further reading on version control systems.

Uploaded by

aahilgazali102
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/ 8

Skill Based Lab IV – DevOPs

Experiment No.: 2

Create and fork repositories in GitHub

20
Experiment No. 2
1. Aim: Create and fork repositories in GitHub
a. Creating a GitHub account
b. Synchronizing repositories.
c. Tagging known commits
d. Reverting changes

2. Objectives: From this experiment, the student will be able


• To understand DevOps practices which aims to simplify Software Development Life.
• To be aware of different Version Control tools like GIT, CVS or Mercurial

3. Outcomes: The learner will be able to


• To understand the fundamentals of DevOps engineering and be fully proficient with
DevOps terminologies, concepts, benefits, and deployment options to meet your
business requirements.
• To obtain complete knowledge of the “version control system” to effectively track
changes augmented with Git and GitHub.

4. Hardware / Software Required : Linux / Windows Operating System

5. Theory:

a. Creating a GitHub account

1. Step 1: Create a GitHub account

The easiest way to get started is to create an account on GitHub.com (it's free).

21
Pick a username (e.g., octocat123), enter your email address and a password, and click Sign
up for GitHub. Once you are in, it will look something like this:

2. Step 2: Create a new repository

A repository is like a place or a container where something is stored; in this case we're
creating a Git repository to store code. To create a new repository, select New
Repository from the + sign dropdown menu (you can see I've selected it in the upper-right
corner in the image above).

Enter a name for your repository (e.g, "Demo") and click Create Repository. Don't worry
about changing any other options on this page.

Congratulations! You have set up your first repo on GitHub.com.


22
3. Step 3: Create a file

Once your repo is created, it will look like this:

Don't panic, it's simpler than it looks. Stay with me. Look at the section that starts "...or create
a new repository on the command line," and ignore the rest for now.

Open the Terminal program on your computer.

Type git and hit Enter. If it says command bash: git: command not found, then install
Git with the command for your Linux operating system or distribution. Check the installation
by typing git and hitting Enter; if it's installed, you should see a bunch of information about
how you can use the command.

In the terminal, type:


23
mkdir Demo

This command will create a directory (or folder) named Demo.

Change your terminal to the Demo directory with the command:

cd Demo

Then enter:

echo "#Demo" >> README.md

This creates a file named README.md and writes #Demo in it. To check that the file was
created successfully, enter:

cat README.md

This will show you what is inside the README.md file, if the file was created correctly.
Your terminal will look like this:

To tell your computer that Demo is a directory managed by the Git program, enter:

git init

Then, to tell the Git program you care about this file and want to track any changes from this
point forward, enter:

git add README.md

4. Step 4: Make a commit

So far you've created a file and told Git about it, and now it's time to create a commit.
Commit can be thought of as a milestone. Every time you accomplish some work, you can
write a Git commit to store that version of your file, so you can go back later and see what it
looked like at that point in time. Whenever you make a change to your file, you create a new
version of that file, different from the previous one.

To make a commit, enter:

24
git commit -m "first commit"

That's it! You just created a Git commit and included a message that says first commit. You
must always write a message in commit; it not only helps you identify a commit, but it also
enables you to understand what you did with the file at that point. So tomorrow, if you add a
new piece of code in your file, you can write a commit message that says, Added new code,
and when you come back in a month to look at your commit history or Git log (the list of
commits), you will know what you changed in the files.

b. Synchronizing repositories

Step: Connect your GitHub repo with your computer

Now, it's time to connect your computer to GitHub with the command:

git remote add origin https://github.com/<your_username>/Demo.git

Let's look at this command step by step. We are telling Git to add a remote called origin with
the address https://github.com/<your_username>/Demo.git (i.e., the URL of your Git repo on
GitHub.com). This allows you to interact with your Git repository on GitHub.com by
typing origin instead of the full URL and Git will know where to send your code.
Why origin? Well, you can name it anything else if you'd like.

Now we have connected our local copy of the Demo repository to its remote counterpart on
GitHub.com. Your terminal looks like this:

Now that we have added the remote, we can push our code (i.e., upload
our README.md file) to GitHub.com.

$ git push [--tags] [remote]


Push local changes to the remote. Use --tags to push tags.

25
$ git push -u [remote] [branch]
Push local branch to remote repository. Set its copy as an upstream.

Once you are done, your terminal will look like this:

And if you go to https://github.com/<your_username>/Demo you will see something like


this:

That's it! You have created your first GitHub repo, connected it to your computer, and pushed
(or uploaded) a file from your computer to your repository called Demo on GitHub.com.

$ git fetch [remote]


26
Fetch changes from the remote, but not update tracking branches.

$ git fetch --prune [remote]


Delete remote Refs that were removed from the remote repository.

$ git pull [remote]


Fetch changes from the remote and merge current branch with its upstream.

c. Tagging known commits

$ git tag
List all tags.

$ git tag [name] [commit sha]


Create a tag reference named name for current commit. Add commit sha to tag a specific
commit instead of current one.

$ git tag -a [name] [commit sha]


Create a tag object named name for current commit.

$ git tag -d [name]


Remove a tag from local repository

d. Reverting changes

$ git reset [--hard] [target reference]


Switches the current branch to the target reference, leaving a difference as an uncommitted
change. When --hard is used, all changes are discarded.

$ git revert [commit sha]


Create a new commit, reverting changes from the specified commit. It generates an inversion
of changes.

6. Conclusion and Discussion:


Students are supposed to write your own conclusion.

7. Viva Questions:
• What is difference between git and github?
• How do you push your project into remote repository?
• Is it possible to revert changes after commit? Is so, how?

8. References:
• Jon Loeliger and Matthew McCullough, Version Control with Git, O’Reilly
Media, Second Edition, 2012.
• Dennis Hutten, Git: Learn Version Control with Git A Step-By-Step Ultimate
Beginners Guide.
• Scott Chacon and Ben Straub, Pro Git_ Everything You Need to Know About
Git, apress, Second Edition.
27

You might also like