Repository navigation
Lab0
In this lab you will create your first local Git repository, connect it to a private remote repository on GitHub, add a README.md file with your student information, and publish your work.
Each task includes both the practical step and the underlying idea so that you understand what Git is doing.
Before creating a repository, install Git on your computer and make sure it is available from the terminal or command prompt.
Official installation page: Git Downloads
Install Git for your operating system:
- Windows: install Git from the official Git for Windows distribution.
- macOS: install Git using Xcode Command Line Tools or a package manager such as Homebrew.
- Linux: install Git with your distribution package manager.
After installation, confirm that Git is available:
git --versionGit is a version control system. A version control system records changes to files over time, allowing you to keep a history of your work and publish that work to shared servers such as GitHub.
In this lab, you will use Git from the command line because it exposes the core workflow clearly and works the same way across different tools and editors.
Create a new folder for this exercise and move into it:
mkdir lab01-git
cd lab01-gitGit does not store projects in a special global place. Instead, each project usually lives in its own normal directory on your computer. When you initialize Git in that directory, Git starts tracking the contents of that project.
Initialize Git in the current directory:
git initThen check the status:
git statusA repository is the place where Git stores the history and metadata of a project. In simple terms, a repository is a project directory managed by Git.
At this stage, the repository is local, which means it exists only on your computer. You can already track files and create history even before connecting to GitHub.
After running git init, look for a folder named .git inside your project directory.
Depending on your operating system and file explorer settings, this folder may be hidden:
- Windows: hidden folders may not appear in File Explorer until hidden items are enabled.
- macOS: hidden files and folders can be toggled in Finder.
- Linux: many file managers hide names starting with
.by default.
If you use the terminal, you can list hidden files with:
ls -laThe .git folder is what makes the directory a Git repository. It contains Git's internal data, such as configuration and project history.
You should understand that .git exists, but you should not manually edit its contents. Git commands manage that internal structure for you.
Sign in to your personal GitHub account and create a new repository with these characteristics:
- Owner: your personal account
- Visibility: private
- Initialization: empty repository
Do not add a README, .gitignore, or license on GitHub. The remote repository should start empty.
GitHub is not Git itself. Git is the version control system running on your machine, while GitHub is a hosting service for remote repositories.
A remote repository is a copy of your project history stored on another server. In this lab, GitHub will store the remote version of your local repository so that you can publish your work and access it from other machines.
Copy the repository URL from GitHub and add it as the remote named origin:
git remote add origin <your-github-repository-url>Check that the remote was added correctly:
git remote -vA remote is a named connection from your local repository to another repository.
The name origin is a common convention for the main remote repository, but it is only a name. What matters is that Git now knows where to send your local history when you decide to publish it.
Create a file named README.md in the repository root.
Add your student information, for example:
# Lab 01
- Name: Your Name
- Student number: Your Student Number
- Course: Web Programming and ArchitectureAfter saving the file, run:
git statusGit tracks files in the working directory, but newly created files are not automatically prepared for the next snapshot.
The README.md file is commonly used to describe a project. In this lab it is also a simple example of content that you will track and publish.
Stage the README.md file:
git add README.mdThen inspect the state again:
git statusThe command git add places changes in the staging area. The staging area is the set of changes that you want Git to include in the next recorded snapshot.
Using git add README.md stages one specific file. This is useful when you want precise control over what will be included next.
You can also stage all tracked and untracked changes in the repository with:
git add --allThis form is broader than git add README.md because it updates the staging area with all current changes, including new files, modified files, and deleted files.
Use git add --all when you intentionally want to prepare every change in the repository for the next commit.
Create your first commit:
git commit -m "Add initial README with student information"A commit is a recorded snapshot of the staged changes together with a message that explains what was changed.
Commits are the core building blocks of Git history. After this step, your local repository contains a first saved version of the project.
Publish the local repository to GitHub:
git push -u origin mainIf your default branch name is not main, use the branch name shown by Git in your local repository.
The command git push sends local commits to a remote repository.
In this command:
-
originis the remote name. -
mainis the branch being published. -
-usets the upstream relationship so that future pushes and pulls can use shorter commands.
In practical terms, git push copies the commit history from your local repository to GitHub.
Open the repository page on GitHub and confirm that:
- the repository is private
- the
README.mdfile is visible - the commit history contains your first commit
Verification matters because version control is not only about running commands. It is also about understanding the state of the local repository and confirming that the remote repository contains what you intended to publish.
git --version
mkdir lab01-git
cd lab01-git
git init
git status
ls -la
git remote add origin <your-github-repository-url>
git remote -v
git add README.md
git add --all
git commit -m "Add initial README with student information"
git push -u origin mainBy the end of this lab, you should be able to explain:
- what Git is used for
- what a local repository is
- why the
.gitfolder exists - what a remote repository on GitHub is
- what
git adddoes - when
git add --allis useful - what
git pushdoes
Before creating the JavaScript program, install Node.js on your computer.
Choose the version recommended for most users (LTS) and follow the installation instructions for your operating system.
After installation, open a new terminal or command prompt and confirm that Node.js is available:
node --versionYou can also check that the Node Package Manager (npm) was installed:
npm --versionNode.js is a JavaScript runtime that allows you to execute JavaScript programs outside a web browser.
In this lab, you will use Node.js to run a simple JavaScript program from the command line. This introduces the basic workflow of creating source code, running it locally, and then tracking it with Git.
Inside your lab01-git folder, create a file named:
hello.js
Add the following code:
console.log("Hello World");Run the program from the terminal:
node hello.jsThe expected output is:
Hello World
Check the repository status:
git statusYou should see hello.js listed as an untracked file.
Stage the file:
git add hello.jsCreate a commit:
git commit -m "Add Hello World JavaScript program"Finally, publish the new commit to GitHub:
git pushThis demonstrates the complete basic Git workflow:
- Create a file in the working directory.
-
Check the repository status with
git status. -
Stage the file with
git add. -
Commit the staged changes with
git commit. -
Push the commit to the remote repository with
git push.
After pushing, hello.js should be visible in your private GitHub repository alongside README.md.
After this section, you should be able to:
- install Node.js and verify the installation
- create a basic JavaScript program
- execute JavaScript using Node.js
- understand the difference between a source file and its output
- add a new file to an existing Git repository
- commit and push additional changes to GitHub.