Getting started with github
Setup github
- Setup SSH key for git
- Adding an SSH key means that each time you make a commit to github, you don’t need to put in your github login information each time. Follow the instructions here. You only need to perform this step once.
- (On Github) Create new repository on your organization’s (i.e. company or academic lab) repository
- Click “new”
- Create a name
- Select a license
-
(On Github) Fork the new repository to your personal repository
- (On Github) Clone the repository to your local machine
- On forked branch click “clone & download”
- In your local terminal run the command:
$ git clone git@github.com:<user name>/<repository name>
- (Local repository) Create upstream branch,
$ git remote add upstream <repository git@github.com:<organization repository name>/<repository name>.git
Make tracked changes using git
- (Local repository) Create a new branch and where to push changes to
$ git checkout -b <branch name> $ git push -u <origin or upstream> <branch name>
This allows you to sync your local repository with the forked repo (your personal Github) and eventually the organization’s repository. If you call
$ git remote -v
you will see that origin is your personal Github and upstream is your organization’s Github. Warning: Do not touch “master” or “upstream/master” branch. - (Local repository) Make changes on your branch by performing the following steps:
$ git add <file name> $ git commit -m “message/description” $ git push
- (On Github) Create a pull request (PR).
At this point you have made significant changes to your personal Github and you would like to add them to the organization’s Github.
- Click “Compare and PR”
- Add reviewer on the right bar
- Add comment
- Click “Create PR”
- Merge PR
- On github PR click “squash and merge”
- On github PR click “delete branch” At this point, the organization’s master branch is at the same level as your personal Github branch and your local repository branch
- (Local repository) Update your local master branch
- Now we need to update your local master AND your personal github master to include the new changes that were on your branch. First, we switch to your local master:
$git checkout master
- Then grab the changes from the organization’s master branch:
$git fetch upstream
- Then merge the changes in the organization’s master with your local master:
$git merge upstream/master
- Now your local master is up to date.
- Push those changes to our github master:
$git push
- Now your personal github master is up to date
- Now we need to update your local master AND your personal github master to include the new changes that were on your branch. First, we switch to your local master:
- Remove local branch
git branch -d <branch name>
- You can continue to make more changes to this repository by going back to #1 and repeat the subsequent steps