Laboratory work (Assignment): Introduction to Working with Git for Beginners
How to submit?
To submit an Assignmen, you need to take a screenshot after each step of the work. Save all screenshots sequentially in a .docx file (Microsoft Word). When you take screenshots of your work in Git, you need to take a screenshot of your account so that I can see that this is your work. After all is done, attach .docs file to this Assignment page.
Objective
The objective of this laboratory work is to study the basics of working with the version control system Git and acquire practical skills in managing projects using Git and the Visual Studio Code editor.
Equipment and Software Required
To complete this laboratory work, you will need the following equipment and software:
o Computer (or laptop) with installed operating system (Windows / Linux / MacOS)
o Installed Git client (download here)
o Editor Visual Studio Code (download here)
Theoretical Part
What is Git?
Git is a distributed version control system designed to track changes in any types of files, especially often used by programmers for collaborative development of source code projects.
Main advantages of using Git:
o Ability to track history of file changes
o Collaborative development of projects by multiple people simultaneously
o Creation and management of various development branches
o Easy restoration of previous states of the project
Practical Assignment
Step 1: Installing and Configuring Git and VSCode
Installing Git
1. Download the Git installation package from the official website at https://git-scm.com/downloads
2. Run the installation and follow the wizard instructions
3. Make sure that Git is installed correctly by opening terminal and entering command:
git
--
version
You should see the version of the installed Git.
Installing VSCode
1. Download the VSCode installation package from the official website at https://code.visualstudio.com/
2. Run the installation and follow the wizard instructions
3. Open VSCode and make sure the interface loads properly
Step 2: Setting Up Git
Open terminal and execute commands to configure your username and email address:
git config --global user.name "Your
Name"
git config --global user.email "
your_email@example.com"
This data will be used to identify your commits.
Step 3: Creating New Project
1. Create new folder for your project (in terminal):
mkdir git_lab_project
cd git_lab_project
2. Initialize new Git repository:
git init
This command creates hidden directory .git
, containing all
necessary infrastructure for working with the project.
Step 4: Creating Project Structure
Create project structure consisting of three HTML files. The first file code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home Page</title>
</head>
<body>
<h1>Welcome to Home Page!</h1>
</body>
</html>
Save this code into file named index.html.
Now create two similar files called page1.html and page2.html with different page titles.
Step 5: Adding Files to Git Index
Execute the following command to add newly created files to staging area:
git add .
This adds all new and modified files to the index.
Step 6: Committing Changes
Commit your changes with the following command:
git commit
-m "Initial commit: created basic project structure with three HTML
pages"
Comment (-m "message"
) helps describe essence of
made changes.
Step 7: Viewing History of Commits
View history of performed commits with command:
git log
It shows list of all committed changes with information about each commit.
Step 8: Working With Branches
Create new branch for experiments:
git branch
experimental_branch
Switch to created branch:
git checkout
experimental_branch
Modify one of the files, e.g., add new paragraph text in index.html.
Return back to main branch master:
git checkout master
Notice that modifications done in experimental branch did not affect main branch.
Merge changes from experimental branch into main branch:
git merge experimental_branch
Make sure changes were successfully transferred into main branch.
Delete experimental branch since it is no longer needed:
git branch -d experimental_branch
Step 9: Working with Remote Repository on GitHub
Registering on GitHub
1. Go to the official platform site: GitHub
2. Click button Sign up (Registration) located in top right corner of screen.
3. Choose free tariff plan (Free plan) and fill registration form:
- Enter unique username.
- Provide valid email address.
- Create strong password.
4. Confirm email address by clicking link sent to specified email.
5. Complete profile setup choosing preferred options and confirm registration.
Creating New Repository on GitHub
1. Log in to your GitHub account.
2. Click plus icon (+) located in upper-right part of screen and select option New repository.
3. Assign name to your new repository (for example, git_lab_project).
4. Optionally provide brief description of repository purpose in field Description.
5. Keep switcher Public enabled if you want to create public repository.
6. Check checkbox Initialize this repository with a README to automatically generate initial file README.md.
7. Additionally, you can choose license and add .gitignore file (recommended for organizing workspace).
8. Press button Create repository to finish creation process.
Linking Local Repository with Remote One on GitHub
1. Copy SSH or HTTPS link to created repository by pressing green button Code on repository page.
2. In terminal run command to add remote repository:
git remote add origin copied_repository_link
3. Verify correct connection to remote repository running command:
git remote
-
v
Pushing Local Changes to Remote Repository
1. Prepare and commit changes locally (add some more paragraphs and commit):
git add
.
git commit
-
m
"Brief message describing
changes"
2. Send changes to remote repository on GitHub:
git push
-
u origin main
Command push transfers local changes onto
remote server while flag -u
establishes connection
between local and remote repositories.
Modifying Files Directly on GitHub and Pulling Updates Locally
1. Access web interface of your repository on GitHub.
2. Find required file and press pencil icon (editing) next to filename.
3. Perform desired edits directly within browser window.
4. At bottom of page write short commit message and click button Commit changes.
5. To download updates from remote repository into your local copy, run command:
git pull origin main
Command pull
merges latest changes from
remote branch main
with your local working copy.
Control Questions
1. What is a version control system?
2. Which basic Git commands have you used during performing this lab work?
3. Why are branches needed in Git?
4. How does git add differ from git commit?
5. How do I view change history in my project?