You may perform these steps on the command line or using your preferred GitHub UI such as GitHub Desktop or VSCode/other IDE git integration. The command line commands are printed below each step. IMPORTANT: In order to run the gh
command line actions, you must first have installed gh cli and authenticated your local machine using the command gh auth login
, then following the prompts.
- 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 the study spaces folder 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
- The maintainer (the instructor) will now review and approve your pull request
- 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 two lines is for reference if you have your own repo.
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
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 web interface or VSCode to resolve the merge conflict
- Delete the branch once you are done merging (using the GitHub web interface, 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: