- 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 branchCreate and switch to branch A:
git checkout -b branch-aConfirm you are on branch A:
git branchAdd a text file to this repo named feature1.txt
touch feature1.txtOpen the text file and add "feature 1" to the feature1.txt file. Example command below:
open feature1.txtAdd 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 statusAdd 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 enterCreate and switch to branch B:
git checkout -b branch-b
git branchAdd a text file to the current branch, branch-b, of this repo named feature2.txt
touch feature2.txtManually open the text file and add "feature 2":
open feature2.txtAdd 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-bResolve any conflicts if they arise and commit the changes.
Switch to the main branch:
git checkout main
git merge branch-aDelete branches A and B locally:
git branch -d branch-a
git branch -d branch-bPush the main branch to your forked repository:
git push origin mainOn 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."