This post is first created by CodingMrWang, 作者 @Zexian Wang ,please keep the original link if you want to repost it.
First step
$ git config --global user.name "Your Name"
$ git config --global user.email "email@example.com"
Create a repository
mkdir github
cd github
git init initialize a git repository
Modify repository
git add file add file to next commit
git commit -m "update" Commit previously staged changes
git commit --amend Change the last commit
git status check status
git diff file Changes to tracked files
Commit History
git log check commit log
Branch
git branch -av List all existing branches
git checkout <branch> Switch to a branch
git branch <new-branch> Create a new branch
git checkout --track <remote/bran-ch> Create a new tracking branch based on a remote branch
git branch -d <branch> Delete a local branch
UPDATE & PUBLISH
git remote -v List all currently configured remotes
git remote show <remote> Show information about a remote
git pull <remote> <branch> Download changes and directly merge/integrate into HEAD
git push <remote> <branch> Publish local changes on a remote
MERGE & REBASE
git merge <branch> REBASEMerge <branch> into your current HEAD
git rebase <branch> Rebase your current HEAD onto <branch>
git rebase --abort Abort a rebase
git rebase --continue Continue a rebase after resolving conflicts
UNDO
git reset --hard HEAD^ go back to last commit
git reset --hard 1094a go back to 1094a commit
git checkout -- file ignore changes
git rm file remove file from repository
Code review Steps:
-
Create new branch
$ git checkout -b codingmrwang
-
Make changes to file and commit your changes
# module should be which part you make changes. Like: view.get_profile # commit message should be what detailed changes you made $ git commit -m "module: commit message"
-
If you have many commit, you need to combine them into one
$ git rebase or # combine last 4 commits $ git rebase -i HEAD~4
-
Push to remote repo
$ git push origin codingmrwang
-
Submit merge request
- Click Create Merge Request button to create merge request
- Assign an Assignee
- Change Target branch tobe the target branch you want to merge (Master)
- Check Remove source branch when merge request is accepted.
- Submit Merge Request
Then the student will receive email to do code review, if ok, accept merge request.