Experiment no 1: Lab Work
• Experiment 1: Version Control with Git
• Objective: Understand and utilize Git for version control.
• Tasks:
• Initialize a Git repository.
• Perform basic Git operations: add, commit, push, pull.
• Create and switch branches.
• Resolve merge conflicts.
• Collaborate using pull requests on GitHub.
Version Control Systems
Before diving deep, let’s explain a scenario
before Git:
• Developers used to submit their codes to
the central server without having copies
of their own
• Any changes made to the source code
were unknown to the other developers
• There was no communication between
any of the developers
Now let’s look at the scenario after Git:
• Every developer has an entire copy of
the code on their local systems
• Any changes made to the source code
can be tracked by others
• There is regular communication
between the developers
What Is GitHub?
• GitHub is a Git repository hosting service that provides a web-
based graphical interface (GUI).
• It helps every team member work together on a project from
anywhere, making it easy to collaborate.
What is Git?
• Git is a version control system used for tracking changes in computer files.
• It is generally used for source code management in software development.
• Git is used to tracking changes in the source code
• The distributed version control tool is used for source code management
• It allows multiple developers to work together
• It supports non-linear development through its thousands of parallel
branches
Features of Git
• Tracks history
• Free and open source
• Supports non-linear development
• Creates backups
• Scalable
• Supports collaboration
• Branching is easier
• Distributed development
Git Workflow
The Git workflow is divided into three states
• Working directory - Modify files in
your working directory
• Staging area (Index) - Stage the files
and add snapshots of them to your
staging area
• Git directory (Repository) - Perform
a commit that stores the snapshots
permanently to your Git directory.
Checkout any existing version, make
changes, stage them and commit.
Branch in Git
• Branch in Git is used to keep
your changes until they are
ready.
• You can do your work on a
branch while the main branch
(master) remains stable.
• After you are done with your
work, you can merge it with the
main office.
Branch in Git
• The above diagram shows there is a master branch.
• There are two separate branches called “small feature” and “large
feature.”
• Once you are finished working with the two separate branches,
you can merge them and create a master branch.
Commands in Git
• Create Repositories • Parallel Development
git init branch
• Make Changes merge
add rebase
commit • Sync Repositories
status push
pull
add origin
• Check the version of Git.
• Set up global config variables - If you are working with other developers, you need to
know who is checking the code in and out, and to make the changes.
• If in case you need help, use the following commands:
This will lead you to the Git help page
on
the browser, which will display the
following:
• Create a “test” repository in the local system
• Move to the test repository.
• Create a new git instance for a project.
• Create a text file called info.txt in the test folder; write something and save it.
• Check the status of the repository.
• Add the file you created to make a commit.
• git add .
• Commit those changes to the repository’s history with a short message.
• Make any necessary changes to the file and save.
• Now that you’ve made changes to the file, you can compare the differences since
your last commit.
• Add GitHub username to Git Configuration.
• Create a remote repository.
• Connect the local repository to your remote repository.
• Push the file to the remote repository.
• Refresh your repository page on GitHub. You will get your local file on your remote
GitHub repository.
• Create three more text files in the local repository - “info1.txt”, “info2.txt”,
“info3.txt”.
• Create a branch “first_branch” and merge it to the main (master) branch.
• The below command switches to the new branch from the master branch.
• The below command creates and adds “info3.txt” to the first_branch.
• Create a branch “first_branch” and merge it with the main (master) branch.
• The below command shows that the new branch has access to all the files.
The below command shows that the master branch does not have an “info3.txt” file.
The command is used to merge
“first_branch” with the master branch.
Now, the master branch has
“info3.txt” file.