Let's start fixing how we use git here in crew so our GitHub looks even more awesome and you all get experience working in a professional-like git environment.
How to use GitHub in the good ways
- Go to the page of the repo you wish commit changes to (I'm using dds-client as an example)
- Fork the repo into your own GitHub account
- Clone your repo onto your computer.
'git clone <x>'
- Add the original repo as a remote
'git remote add upstream https://github.com/crew/dds-client.git'
- Okay! Now you're set up to do git in the right way. Follow a few more examples of common things and you'll git better than most
How do I develop in this newfangled method?
Everything you do should be related to an issue on GitHub. Let's go through the process of making one.
Making issues on GitHub
- Click the 'issues' tab on the repo page
- Make a new issue!
- Fill out all the fields to the best of your ability
Notice how once you submit the issue, it gets a number? This number does a really cool thing for us later when we...
Make a pull request for the changes we made that fix the issue
There are a couple ways of doing this, but the easiest is to push a branch you want to merge to the upstream repo:
$ git checkout dev # the branch we want to make changes based on
$ git fetch upstream # fetch all remote branches
* [new branch] lolwhatever -> upstream/lolwhatever
* [new branch] someone-elses-pull-request -> upstream/someone-elses-pull-request
$ git merge upstream/dev # merge the current work on the dev branch into our local copy
$ git checkout -b change-readme # checkout a new branch with a name that relates to what issue you are working on
Switched to a new branch 'change-readme'
$ vi README.md # make your changes and stuff
$ git status # always a good command to look at
On branch change-readme
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
$ git add README.md # add tracking to the changes you just made
$ git commit -m "Updated README.md to add info about xyz"
$ git push upstream change-readme # !!! this pushes your code to a new branch on the upstream repo
Counting objects: 9, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 321 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
* [new branch] change-readme -> change-readme
On the GitHub side:
- A magic button appears, click it!
- Oh wow a pull request!
Couple things to note here:
Make sure the thing I circled is right, if the branch isn't the right one, click the edit button
Use the phrase "Closes #<x>" to have GitHub automatically close the issue when someone else merges your pull request
Give a good description of what you did, it's Markdown, so you can have lists and images too.
- Once you've created the pull request, add some labels
- Don't merge it yourself! This is the most important part of coding: code review
Code review is fun and makes you a better developer
People should complain that you did things wrong at this point
You can comment directly on lines in the code, and you should. Unknown User (aliukani) helped me out here by telling me that I did something that isn't good.
Let's see exactly what he's talking about by viewing the code that he's complaining about:
Yeah, this wasn't what I wanted to do, I'm using too many characters because of code style and things. Let's go back to development and fix things up.
Make your code changes and commit them. Push the changes upstream when you're happy with your effort.
Notice how the pull request updates automagically! Ping your friends to look again and do more code review.
Look at how Unknown User (aliukani) added an approval label (you can make these by going to issues -> labels -> new label).
Hey Unknown User (alice) also approved! Now that we have a few (not zero or one!) people that think that this is good code and works.
Now a maintainer that is willing to put their name behind your code can endorse it and merge your pull request.
Now you can click the 'Delete branch' button and now you're done! It also closes the issue! Everyone is happy!