We will be running through this repo using first the command line and then GitHub Desktop or VSCode git integration.
These steps will primarily happen on the command line. Make sure you have the GitHub CLI installed and authenticated if you want to use the command line to do the pull request. Otherwise, you can use the GitHub website.
- Break into pairs
- Fork this repo (and name the forked repo
github-intro-YOURNAME
) - Clone your forked repo onto your local computer
git clone https://github.com/YOURUSERNAME/github-intro.git
- Open the repo folder in VSCode or your preferred text editor
- Add a file to study spaces recommending a good place to do computer work near Harvard
- Commit your changes
git add FILENAME
git commit -m "Add study spaces file"
- Push your changes to your forked repo
git push
- Open a pull request to merge your changes into the original repo (can also do this on the GitHub website)
gh pr create
- Review your partner's pull request and merge it into the original repo (can also do this on the GitHub website)
- Note that the maintainer (an informatics staff) will have to approve the pull request, as this repo is owned by the informatics organization. So the below is for demonstration purposes only
gh pr checkout PRNUMBER
gh pr merge
- On your fork, sync your fork so your repo is updated (Do this on the github website)
- Pull the changes from the your fork into your local repo
git pull
Here is a diagram of what you'll be doing in this part:
Now we will be working on GitHub Desktop, the GitHub website, or VSCode git integration. Use whichever GUI you prefer. The equivalent command line commands to GUI options are printed below each step. We will be creating a branch and then working on the same file on two different branches to create a merge conflict. Branches are great for experimenting on a feature or fixing a bug without affecting the main code, but they can cause merge conflicts if two branches change the same line of code.
Example of branching:
gitGraph
commit
branch bugFix
commit
commit
commit
checkout main
merge bugFix id: "merge"
commit
- Open your forked repo in your preferred text editor
- Create an empty file called
haiku_yourname.md
in thehaikus
folder and commit & push itgit add haikus/haiku_yourname.md
git commit -m "Add empty haiku file"
git push
- Start a new branch called
haiku-test
(substituting your name for NAME)git checkout -b haiku-test
- Write 1-2 lines of the haiku and save it in the
haikus
folder - Commit your changes & push it
git add haikus/haiku_yourname.md
git commit -m "Add haiku lines"
git push
- Switch back to branch
main
and observe that your haiku is still emptygit checkout main
cat haikus/haiku_yourname.md
- Write a line in your empty haiku and commit & push it
git add haikus/haiku_yourname.md
git commit -m "Add haiku line"
git push
- Open a pull request from
haiku-test
and try to merge it intomain
gh pr create
gh pr checkout PRNUMBER
gh pr merge
- Use the GitHub interface or VSCode to resolve the merge conflict
- Delete the branch once you are done merging (using the GitHub web interfact, command line version printed for reference)
git branch -d haiku-test
- (Optional) Submit a pull request to the original repo with your haiku so we can all see it!
For reference, this is the gitflow diagram for the above steps: