GitHub Workflow
These slides will review the following:
To start off…
Image of Overall Structure of Repository
Our group GitHub repository (online)
These are the copies of our code that are kept in the repo:
MAIN: source-of-truth, end version for deployment
DEV: working copy that has all our merged code in it. We all share this.
INDIVIDUAL WORKING BRANCH: where you complete your coding task
INDIVIDUAL WORKING BRANCH: where you complete your coding task
INDIVIDUAL WORKING BRANCH: where you complete your coding task
INDIVIDUAL WORKING BRANCH: where you complete your coding task
INDIVIDUAL WORKING BRANCH: where you complete your coding task
No interaction with main occurs until ready for deployment
Merges from individual working branches into dev are controlled by branch protection rules set by the admin, usually involving pull requests and approvals of your code by another collaborator
The individual working branches that are stored in the repository are basically records of the code you have merged into dev.
Working in this way, abstracted away from our shared code bank, means that if we create a breaking error we can’t fix, we can revert to dev and reset our version. No code lost!
To view all the branches, on our repository’s main page, follow the images below:
Click here
dev is set as the default branch, which means all changes we push up from our local working branches merge into this one.
The local branches (and main) are listed here. I called this branch `nkc-1` when I created it. It’s where I’m making all my changes, and I’ll merge it into dev when my most recent task is done.
Takes you here
Image of What’s on Your Local Computer
On Your Local Computer:
These are the copies of code that are kept on your machine.
The big arrows represent the flow of code.
DEV: this is NOT the real dev that is in the repo, this is YOUR COPY of that code that you made when you cloned the repo to your machine.
Keeping this local copy up-to-date by pulling after anyone merges code into the repo will ensure you can avoid conflicts and errors when you push yours up
YOUR CURRENT WORKING BRANCH: this is the branch copy that you make to complete a specific coding task.
When the task is completed, you will check to make sure that you can successfully merge your changes into the repo, and push this branch up.
When you first clone the repo, a copy of dev is made to your local computer system.
After anyone merges changes into the repo, and before you push your changes up, you pull the most recent version of the dev that lives in the repo to the copy of the dev that lives in your machine.
You never do your work in this branch, and you never push to the repo from this branch. This is your local back up of the code that exists in the repo.
Anytime you update your copy of dev by pulling from the repo, you need to merge it into your local working branch. This will catch any conflict early so you can fix them more easily.
You always merge dev into your working branch, not the other way around.
Ideally, every time you merge your changes (i.e., complete a task), you should ideally create a new unique working branch for your next one.
Once your task is finished and you’re ready to merge it into dev (meaning you’ve already updated your local copy of dev and merged it into your working branch), you push the working branch up to the repo version of dev.
You don’t pull from the repo into this branch.
Commands: Cloning a Repo (via terminal)
z
Copy your chosen link to paste into your terminal
…then…
…then…
Commands: Creating a New Branch
I did not pick a good branch name! I should have been more descriptive.
Commands: Committing
Commands: Pulling from the Repo
Whenever someone completes a task and merges it into the online GitHub repo, everyone should pull to update their local copy of dev (including the person that just pushed). This will ensure that everyone is working with the most up-to-date version of the app, avoiding a lot of headaches and conflict fixes down the road.
These teeny-tiny buttons are what you push to choose which version you want to keep
Your code
The conflicting code you’re trying to merge in
Commands: Pushing Your Changes to the Repo
YOUR CURRENT WORKING BRANCH:
You’ve completed your current task. Time to get ready to push! Save/stage your progress:
git add .
…then…
git commit -m “commit message here”
When you’re done with your current task and ready to push your code to the repo, first commit your changes (see slide 7 & picture)
Then switch into your local copy of ‘dev’.
Then switch back to your local branch.
Merge the updates to your local dev copy into your working branch to check for conflicts. If there are any, fix them and recommit.
Pull from the repo just to make sure you really are up to date (sometimes you get a surprise!)
Push your code up to the repo, then go online to the GitHub repository for the final steps!!
1
2
3
4
5
6
Procedure: Initiating a Pull Request on GitHub
That’s it! Your request to merge is in. Let the team know you need your request reviewed and merged!
And don’t forget: once your changes are merged into the dev branch on GitHub, pull them down to your local copy of dev as well, to keep up to date.
When you open the GitHub repo online, you will see an alert that says you have made a push, and you need to initiate a pull request. Click on the green “Compare & pull request” to begin.
1
You’ll be taken to this screen. Make any comments you like, then hit the green “Create pull request” button.
2
Your pull request is in! Now let the rest of the team know that you need it reviewed, approved, and merged into the dev branch on GitHub. Once it’s merged, the red will disappear, and the green “Open” tag will turn purple.
3
Procedure: Reviewing & Approving a Pull Request on GitHub
When someone has a pull request submitted that needs approval, someone should verbally (or, you know, through a message) acknowledge that they are going to deal with it, to make sure everyone’s upto speed.
Open your GitHub account and look where it says “Pull requests” up top. If there’s a number next to it, there re requests that need reviewing. Click on it.
When you’re brought to this screen, click on the pull request you’d like to view.
You will be brought to this screen, this time as the reviewer of someone else’s pull request.
Click on “Add your review”. Have you ever seen such a tiny important link?
Old code
New code being pushed
You’ll be brought to a window and shown the changes that your colleague made. Review them and see if you have any questions.
Once you’re satisfied that it all looks good, hit the green “Review changes” button.
This modal will then pop up. You can leave a comment in the window if you like, but the important part will be to click the “Approve” radio button before you hit the green “Submit Review” button.
1
2
3
4
5
Approving: Last steps
Confirm Merge
Click
…then click
Purple means success!
OK, very last steps! Now you just need to merge their changes into the GitHub ‘dev’ branch.
Click green “Merge pull request” button, followed by green “Confirm merge” button, and if you see the top bubble alert turn purple and say “Merged,” you’re all done!! Yay!!!
OK, that was a run –through of the GitHub basics! Lemme know if you need any help!
6
7