You will perform three tasks in this exercise.
- Create and fix a merge conflict
- Amend a commit
- Create and approve a pull request
It is strongly recommended that you use a git extension for your IDE to complete this lab. If you are using Visual Studio Code, you can use the GitLens extension.
- Fork this repository to your GitHub account.
- Clone the forked repository to your local machine.
- Open the repository in your IDE.
- Create a new branch called
merge-conflictfrommainbranch. - Create a new file called
the-conflict.txtand add the following text to it:
This file will cause a merge conflict
- Commit the changes to the
merge-conflictbranch. Make sure you add a meaningful commit message. - Switch back to
mainbranch. - Create a new file called
the-conflict.txtand add the following text to it:
Peace not conflict is the way forward
- Commit the changes to the
mainbranch. Make sure you add a meaningful commit message. - Merge the
merge-conflictbranch into themainbranch. - Resolve the merge conflict by keeping the following text in the file:
Sometimes to make peace you need to compromise
- Commit the changes to the
mainbranch. Make sure you add a meaningful commit message.
- Create a new branch called
amend-commitfrommainbranch. - Create a new file called
amend-commit.txtand add the following text to it:
This file will be amended
- Commit the changes to the
amend-commitbranch. Make sure you add a meaningful commit message. - Amend the commit by adding the following text to the file:
This file has been amended
- Commit the changes to the
amend-commitbranch. Make sure you add a meaningful commit message.
- Create a new branch called
pull-requestfrommainbranch. - Create a new file called
pull-request.txtand add the following text to it:
This file will be merged via a pull request
- Commit the changes to the
pull-requestbranch. Make sure you add a meaningful commit message. - Push the
pull-requestbranch to the remote repository. - Create a pull request to merge the
pull-requestbranch into themainbranch. - Approve the pull request.
- Merge the
pull-requestbranch into themainbranch.
git checkout -b <branch-name>- creates a new branch and switches to itgit checkout <branch-name>- switches to the specified branchgit merge <branch-name>- merges the specified branch into the current branchgit status- shows the status of the current branchgit add <file-name>- adds the specified file to the staging areagit commit -m "<commit-message>"- commits the staged changes with the specified commit messagegit log- shows the commit historygit log --oneline- shows the commit history with each commit on a single linegit log --oneline --graph- shows the commit history with each commit on a single line and the branches graphgit push origin <branch-name>- pushes the specified branch to the remote repositorygit pull origin <branch-name>- pulls the specified branch from the remote repositorygit branch -d <branch-name>- deletes the specified branchgit commit --amend- amends the last commitgit push origin --delete <branch-name>- deletes the specified branch from the remote repository