- Creating branches
- Merging changes
- Managing branches in Git
- A GitHub account.
- Git installed on your local machine.
- From this GitHub repository.
- Click on "Fork" above to create a copy in your GitHub account.
Clone the forked repository to your local machine:
git clone [URL of your forked repository]
Replace [URL of your forked repository]
with the actual URL of your fork.
Navigate to your repository:
cd [repository name]
Check the current branch using the command below (should be main
):
git branch
Create and switch to branch A:
git checkout -b branch-a
Confirm you are on branch A:
git branch
Add a text file to this repo named feature1.txt
touch feature1.txt
Open the text file and add "feature 1" to the feature1.txt file. Example command below:
open feature1.txt
Add the text "feature 1" to the file, save and close the editor.
Go back to your terminal and check the status of your git:
git status
Add and commit the change:
git add feature1.txt
git commit -m "Add feature 1"
Switch to the main branch and check the current branch:
git checkout main
git branch
ls and enter
Create and switch to branch B:
git checkout -b branch-b
git branch
Add a text file to the current branch, branch-b, of this repo named feature2.txt
touch feature2.txt
Manually open the text file and add "feature 2":
open feature2.txt
Add the text "feature 2" to the file, save and close the editor.
Add and commit the change:
git add feature2.txt
git commit -m "Add feature 2"
Switch to branch A and merge branch B into it:
git checkout branch-a
git merge branch-b
Resolve any conflicts if they arise and commit the changes.
Switch to the main branch:
git checkout main
git merge branch-a
Delete branches A and B locally:
git branch -d branch-a
git branch -d branch-b
Push the main branch to your forked repository:
git push origin main
On GitHub, navigate to your forked repository and create a pull request to the original repository. Title your PR "Merge branch-b into branch-a: Add both files."