Welcome to IDP Dissemination Branch's walkthrough on merge conflicts. The intent is to teach you how to create a merge conflict, then resolve it. This tutorial uses Visual Studio Code (hereafter VSC) to manage the merge, and a simple hello world
script to demonstrate how it all works.
The git repo used in this tutorial is set to private, so there are a number of items you need to have correctly configured prior to proceeding. Additionally, as we use VSC to provide a user interface to manager the merge process, you're going to need that too.
- a public/private key pair configured to work with github
- membership of the gss-cogs github organisation
- Visual Studio Code1
- Github Pull Request extension
1 There is no obligation to change to VSC as your IDE. There may be a few additional steps which are not noted here, like authenticating VSC to github. Follow the prompts, it's a series of authorisations required.
You will resolve a merge conflict created when merging an existing branch to main. Then you'll create a new branch, modify the main branch, note that there is infact a merge conflict and then you leave it for someone to clean up.
Many of the commands are issued from the Command Pallet, open it using the keystroke ⌘ + shift + P
.
- Fork the github repo using the website. From (httpshttps://github.com/GSS-Cogs/git-walkthrough), click on 'Fork' in the upper right corner. You'll save it to your local account, and use the url you genernated below.
- Clone the github repo
git@github.com:[username]/git-walkthrough.git
using Visual Studio Code- Command Pallet:
git: clone
, paste/typegit@github.com:GSS-Cogs/git-walkthrough.git
- You can explore the repo, and its current branches at (https://github.com/GSS-Cogs/git-walkthrough)
- Command Pallet:
- Open
main.py
in Visual Studio Code. In the current example ourhello world
isHi World
. Yours will be different. - Check what branches are there to merge with a click on the branch icon in the bottom right of VSC's window.
Right now there my local
main
,origin\main
, andorigin\HEAD
are all on the same commit ID. There is another remote branchorigin\italian
. - It's the
origin\italian
branch we will merge. Joy of joys. Let's get that started.- Command Pallet:
Git: merge branch
, then select the repo, then the branch you want to merge from - Disaster! We now have a merge conflict. This is denoted by a violet C in your editor beside the file(s) which have conflicts.
- But fret not. Unless you've committed conflicting Jupyter Notebooks, python files are fairly straightforward to merge.
- Command Pallet:
- Choose which change(s) to accept. In this case we prefer the more continental 'Ciao mondo' over the trite sounding 'Hi world'.
- Stage then commit. There are two ways to do this.
- Pull and Push. There are two ways to do this.
- At this point, condragulations. You've successfully managed a merge conflict. Now's the time to to set one up for the next person to run the walkthrough.
You are not done yet. Time to screw it up all over again. There are no screenshots/GIFs here because the commands are now familiar.
- Create a new branch using the name of the language you will use, I will use french. Chose another language. Push the branch to origin. (You can't pull a branch that doesn't exist yet.)
- Command Pallet:
Git: Create branch from
name the branchfrench
, have it based offmain
. - Command Pallet:
Git: Push
- Command Pallet:
- Checkout main. Change the output back to English.
- Command Pallet:
Git: Checkout
and selectmain
. - Change the text back to
Hello world!
- Save and pull/push
- Command Pallet:
- Checkout
french
. Change the output to French. Save and pull/push. - Finally delete the original branch online at https://github.com/GSS-Cogs/git-walkthrough/branches but not the one you created.