Create a Git Repository, Make Changes, and Manage Branches.
Course Title: Mastering Development Environments Section Title: Version Control Systems Topic: Create a Git repository, make changes, and manage branches.(Lab topic)
Objective: By the end of this lab, you will be able to create a new Git repository, make changes to the repository, and manage branches.
Prerequisites: You have completed the following topics:
- Setting up Git: Installation, configuration, and basic commands.
- Working with Git repositories: cloning, committing, branching, and merging.
Step 1: Create a New Git Repository
To create a new Git repository, follow these steps:
- Open your terminal or command prompt and navigate to the directory where you want to create your new repository.
- Use the
git init
command to initialize a new Git repository.git init my-repo
- Change into the newly created repository directory.
cd my-repo
- Verify that the repository was initialized correctly by using the
git status
command.git status
Step 2: Make Changes to the Repository
Now that we have created a new repository, let's make some changes to it:
- Create a new file called
readme.txt
with the following content:# This is my first repository
- Use the
git add
command to stage the new file.git add readme.txt
- Use the
git commit
command to commit the changes with a meaningful commit message.git commit -m "Initial commit"
Step 3: Create a New Branch
Now that we have made changes to the repository, let's create a new branch to isolate our changes:
- Use the
git branch
command to create a new branch calledfeature/new-feature
.git branch feature/new-feature
- Use the
git checkout
command to switch to the new branch.git checkout feature/new-feature
- Verify that you are now on the new branch by using the
git branch
command with the-v
option.git branch -v
Step 4: Make Changes to the New Branch
Now that we are on the new branch, let's make some changes:
- Edit the
readme.txt
file to include the following content: ```markdownThis is my first repository
This is a new feature
2. Use the `git add` command to stage the changes.
```bash
git add readme.txt
- Use the
git commit
command to commit the changes with a meaningful commit message.git commit -m "Added new feature"
Step 5: Merge the New Branch into the Master Branch
Now that we have made changes to the new branch, let's merge it into the master branch:
- Use the
git checkout
command to switch back to the master branch.git checkout master
- Use the
git merge
command to merge the new branch into the master branch.git merge feature/new-feature
Conclusion: In this lab, we created a new Git repository, made changes to the repository, and managed branches. We learned how to use the git init
, git add
, git commit
, git branch
, git checkout
, and git merge
commands to manage our repository.
Additional Resources:
- For a comprehensive Git documentation, visit https://git-scm.com/docs
- For a beginner-friendly Git tutorial, visit https://guides.github.com/activities/hello-world/
What Next:
- In the next topic, we will cover 'Understanding containerization and its benefits.' From: Containerization with Docker.
Please note that this lab assumes you have completed the previous topics in the course. If you have any questions or need further assistance, please comment below.
Images

Comments