Thursday, July 23, 2015

Intro

Here is a tutorial I created, pdf.

Branch

To list current branch
git branch
To list all branches
git branch -a
To start a new branch, called leiming
git branch leiming git branch -a
To checkout this new branch
git checkout leiming
To combine new and checkout together
git checkout -b leiming
After your branch modification, you can push your local branch code to remote.
git push origin leiming
To fetch the remote branch to local
git pull origin leiming

Fork and Sync

You can fork a repo from some interesting project. If you want to contribute, you need to sync your forked repo back to the original repo. Here are the procedure. (please refer to https://help.github.com/articles/syncing-a-fork/, if you have any problems)

[1] git remote -v
Check what is your origin stream. If you have upstream (original repo), it will show too.

You can use the following command to add your upstream repo.
$git remote add upstream https://github.com/xxxx/yyyy.git

Use $git remote -v, to double check the upstream has been added!

[2] git fetch upstream
get the upstream info

[3] git checkout master
work on your origin/master branch, which is a local version

[4] git push origin master
After your commits, upload your edits to the remote repo.

[5] create a pull request from your github.com account webpage
The upstream repo owner will receive your request and will work on your pull request!

                                               Clean up local repo by syncing with the remote
git fetch origin
git reset --hard origin/master
git clean -f -d