Disclaimer: I'm not an expert at git, this is simply a written guide from Prof Stolley's lectures on 03-04-2019 and 02-19-2020. I just thought it would be a helpful thing to have.
After creating an organization and a repository on GitHub, these are the things you have to do.
This allows you to create a personal copy of the team repository to work with. By having a forked copy of the repo, you'll be able to develop and play and mess around with the code without changing the team's copy!
- Fork
- Click Fork from your organization's group repository
- You'll then be redirected to your own forked repository
- Clone
- Click 'Clone or Download' from your personal forked repository
- Copy link
- In your command line, navigate to the directory where you'd like to your repository to be in
git clone [your-clone-link]
- Add Remote link
- Go to your group's repository on GitHub
- Copy clone link (similar to step 2 above)
- In your command line, navigate into your cloned directory
git remote add [remote-name] [group-repo-clone-link]
- 'remote-name' is the name you'd like to use to reference your team's repository
- Ex.
git remote add group git@github.com:team/this-project
- To check your setup:
git remote -v
- There should be values for 'origin' and your remote name
From the master branch, you should create feature/development branches. The master branch is supposed to be your best working version so far. This is the same version as your team repository's master branch. From your master, create branches for every feature you're working on. Name it descriptively as well (ex: order-form-submit-btn).
- Make branch (per feature)
- From master branch:
git checkout -b [branch-name]
- This command allows you to create and go into your new branch
- From master branch:
- Do your development work here. Git add and commit as usual
- Push to your remote repository, specifying the branch name.
git push origin [branch-name]
Delete branches after they've been merged to master or after tagging.
- Checkout to master branch:
git checkout master
- Delete branch:
git branch -d [branch-to-be-deleted-name]
- If error appears because this branch hasn't been merged, use force delete:
git branch -D [branch-to-be-deleted-name]
- If error appears because this branch hasn't been merged, use force delete:
To delete your branch remotely:
- Go to your master branch
- Delete:
git push origin :[branch-to-be-deleted-name]
You can also do this on the GitHub interface.
A Pull Request is basically you asking the team if your work is worthy enough to be part of the project. By creating a PR, others will be able to see your proposed additions or changes and decide if it'll be merged.
- Go to GitHub -> your forked repository
- Click Pull Request
- You should see a notification there with a clickable 'Pull Request' link
- You'll be redirected to the team repo
- Fill up fields
- Click 'Create Pull Request'
As a part of this team, you're not only making changes, you're reviewing them too. So don't forget to check on your team repository's pull requests!
To check others' pull requests:
- Go to group repo -> 'Pull Requests'
- Click on the earliest commit
- Comment notes or edit if necessary
- 'LGTM' is a common comment meaning 'looks good to me'
- Alternately, you could also point out some issues or fixes
- Last person to check it should merge pull request if there's a unanimous LGTM
The team's master branch has been updated! You should probably update yours too. This makes sure that any work you do fits with the team's development so far. It will also make merges easier for everyone when you do a PR. Do this often.
git pull [remote-name] master
Ex. git pull group master
This happens when there are new updates on the master branch that doesn't exist or clashes with your PR (for example: a new PR might have been merged just before yours). You will need to resolve this by rebasing.
-
Add a comment about the error then continue and click 'Create Pull Request'
-
Resolve your conflicts locally (don't click the 'Resolve' button on GitHub)
a. Update master branch
- Go to master branch:
git checkout master
- Update your master branch from team repo:
git pull group master
- Push updated master branch to your remote repo:
git push origin master
b. Rebase
- Move into your feature branch:
git checkout [branch-name]
- Rebase:
git rebase master
- This will rebase your branch with the master (which is updated from the team repo)
- If successful, check your PR on GitHub. It should let you know that your PR will be able to merge.
- Go to master branch:
- Manually edit
- Open file in Atom and manually edit what should be kept
- Complete rebase
git add [filename]
git rebase --continue
- Push to branch
git push origin [branch-name]
- !ERROR will occur but it's okay
git push origin [branch-name] -f
- Check
- Check your PR on GitHub. It should let you know that your PR will be able to merge.
This will allow GitHub toβsort ofβput a pin at a point in your development. Tagging will let GitHub help you in creating a Release as well.
To tag: git tag [tag-name]
For example: git tag 1.0.0
- Checkout to new branch with tagged version
git checkout -b [new-branch-name] [tag-name]
- This will create a new branch and move you into it. This branch will have the state of your project from the version when you tagged it.
- Ex.
git checkout -b 1.0.1 1.0.0
- Tag this
git tag [tag-name]
- Ex.
git tag 1.0.1
- Push to Git
- Delete your branches locally and remotely. View instructions here.
- After you've tagged the version of your project you want to release, go to your GitHub repository
- Click on 'Releases' tab
- You should be able to view your tags here
- On the tag you'd like to release, click the three-dotted icon on the right -> 'Create Release'
- Fill out fields and the release summary, referring to specific commits
- Select 'Create Release' or 'Save Draft'