Lab 3: Version Control Basics
In this exercise we will learn some of the common version control basic commands we use on everyday basis.
– Learn and practice basic Git commands (add, commit, push, pull, branch).
– Create and merge branches within your Git repository. Give details step by step instruction for this lab with explanation and handon practices
Step 1: Clone Repository
1. Clone Repository: If you haven’t already, clone the Git repository you created in Lab 1 to your local machine using the `git clone` command.
git clone <repository-url>
2. go to the repository “cd <repository name>”
Step 2: Basic Git Commands
1. Create a New File: Create a new text file in the repository directory using a text editor.
2. Stage Changes: Use the `git add` command to stage your changes for commit.
git add <file-name>
3. Commit Changes: Commit your changes with a descriptive commit message.
git commit -m "Added a new file"
4. Push Changes: Push your committed changes to the remote repository.
git push origin main
Step 3: Creating and Merging Branches
1. Create a New Branch: Create a new branch using the `git branch` command.
git branch branch2
2. Switch to New Branch: Use the `git checkout` command to switch to the new branch.
git checkout branch2
3. Make Changes: In the new branch, make some changes to existing files or create new files.
4. Stage, Commit, and Push: Stage, commit, and push your changes to the new branch.
git add .
git commit -m "Made changes in branch2"
git push origin branch2
5. Merge Branches: Switch back to the `main` branch and merge the changes from the branch2.
git checkout main
git merge branch2
6. Push Merged Changes: Push the merged changes to the `main` branch.
git push origin main
Explanation:
– Version Control: Git is a distributed version control system that helps manage changes to your codebase over time.
– Branches: Branches allow you to work on different features or fixes simultaneously without affecting the main codebase.
– Basic Commands: `git add` stages changes, `git commit` saves changes, `git push` sends changes to the remote repository, and `git pull` fetches changes from the remote repository.
– Creating a Branch: Creating a branch is like making a copy of the code at a specific point. You can work on changes in isolation.
– Merging Branches: Merging integrates changes from one branch into another. In this case, we merged the changes from the `branch2` into `main`.
By following these steps and explanations, you’ve learned basic Git commands, created and switched between branches, made changes, and merged branches. This is essential for collaboration and managing different code features and bug fixes in a project.