-
Notifications
You must be signed in to change notification settings - Fork 290
Github Rules
Welcome to the Auto-PyTorch wiki!
You can also check General guideline.
When cloning a new project from not your repository,
you need to define the reference name for the remote repository.
(Plus, do not forget to push Fork
button in the GitHub GUI.)
Conventionally, we name it upstream
.
git remote add upstream git@github.com:automl/Auto-PyTorch.git
Additionally, you have to add your repository as the origin.
$ git remote add origin https://github.com/<Your user name>/Auto-PyTorch.git
If you made a mistake when you add origin
,
you can re-do it as follows:
$ git remote rm origin
$ git remote add origin https://github.com/<Your user name>/Auto-PyTorch.git
Choose appropriate files for the branch and edit them. Do not make changes longer and avoid increasing the number of changed files as much as possible. We would rather recommend to create a new branch.
[References]
- How to Split Pull Requests – Good Practices, Methods and Git Strategies / Git strategy 3. Sequential PRs of “milestone” commits
- When should I create a new branch? Stack overflow
- Checkout the branch and create a new branch Follow the project naming rules.
$ git checkout <target branch name>
$ git checkout -b <new branch name>
- Work on the new branch and send a PR If the target branch is updated, update this branch.
# Forked repostiory
$ git pull --rebase origin <target branch name>
# Otherwise
$ git pull --rebase upstream <target branch name>
NOTE: Since it can overwrite your local change, do not forget to take a backup for your changes.
If the target branch is merged, make the base branch <remote branch name>
, otherwise, keep the base branch the target branch.
$ git status
It would be better to add files one by one rather than using the -all options.
$ git add <file>
This commit message should follow the project rule.
# If the changes are small
$ git commit -m “<commit message>”
# Otherwise, add the body
$ git commit
Note that commit message with the body works when you setup the git commit template described in 2.2.
Before pushing, fetch the latest version. In the case of working on a forked repository, fetch from upstream.
# Forked repository
$ git pull --rebase upstream <remote branch name>
# Otherwise
$ git pull --rebase origin <remote branch name>
NOTE: Since it can overwrite your local change, do not forget to take a backup for your changes.
Fix the files properly.
These changes lead to the changes of others’ commits,
so it would be better to discuss the changes in advance.
Note that incoming change
is the change that you made
and current change
is the change that
you get from the remote repository.
After the changes, add files one by one.
$ git add <fixed file>
Complete rebase.
$ git rebase --continue
$ git push origin <local branch name>
Send a pull request from the GitHub website. When sending a PR, follow the rules specified in 2-3-A. NOTE: Push the green button saying New pull request.
We often encounter the situation where we get a lot of old commits in PR. In this case, we have to apply the following:
$ git checkout <local branch name>
# Forked repository
$ git pull --rebase upstream <remote branch name>
# Otherwise
$ git pull --rebase origin <remote branch name>
$ git push origin <local branch name>
Repeat step 1.3. ~ 1.7. until the PR is merged to the remote repository.
When we merge PR, we would use Squash and merge
instead of Create a merge commit
from the Github webpage.
# Forked repository
$ git pull --rebase upstream <remote branch name>
# Otherwise
$ git pull --rebase origin <remote branch name>
# When there are conflicts, do the following after editing
$ git add <conflicted file>
$ git commit -m "[fix] Resolve merge conflict by incorporating incoming changes"
When you would like to rebase after the Squash and merge
,
you may need to handle rebase --continue
many times
and it is time-consuming.
One way to avoid this is the following:
$ git checkout <current branch name>
# Take the log for the post-processing
$ git log
$ git checkout <branch to rebase>
$ git branch -m <current branch name> <another name>
$ git branch -D <another name>
$ git checkout -b <current branch name>
$ git cherry-pick <commit hash to put on the top>
$ git branch --delete <local branch name>
$ git push --delete origin <deleted branch name>
First, the main branches for each repository should have main
and stable
branches.
main
branch is a working branch and stable
branch is a branch that provides stable functionalities as intended.
The branch name should look like the following:
# <Issue Tracker ID>-<work type>-<work description>
123-feature-add-foo-function
There are four rules for naming.
- The name always starts from the issue ID in the Github webpage
- Work type is listed in the table below
- Use a short and recognizable name
- The delimiter must be hyphens
work type | description |
---|---|
hotfix | branch from stable and urgent work |
feat | branch from main and work on new feature |
fix | branch from main and fix some issues |
refactor | branch from main and work on refactoring |
[References]
The details are mentioned in the reference below.
Basically, the commit message should specify why you make the changes
because people will know what you changed from git diff
and cannot know why from the git commands.
There are seven rules to follow:
- Start with a tag
- Separate subject from body with a blank line
- Limit the subject line to 50 characters
- Capitalize the first word of the subject line
- Do not end the subject line with a period
- Use the imperative mood in the subject line (not -ing or -ed)
- Make new lines every 72 characters in the body
- Use the body to explain what and why vs how
Create the file ~/.github/.gitmessage
and paste the template below:
# [<tag>] (If applied, this commit will...) <subject> (Max 72 char)
# |<---- Preferably using up to 50 chars --->|<------------------->|
# Example:
# [feat] Implement automated commit messages
# (Optional) Explain why this change is being made
# |<---- Try To Limit Each Line to a Maximum Of 72 Characters ---->|
# (Optional) Provide links or keys to any relevant tickets, articles or other resources
# Example: Github issue #23
# --- COMMIT END ---
# Tag can be
# feat (new feature)
# fix (bug fix)
# refactor (refactoring code)
# style (formatting, missing semi colons, etc; no code change)
# doc (changes to documentation)
# test (adding or refactoring tests; no production code change)
# version (version bump/new release; no production code change)
# jsrXXX (Patches related to the implementation of jsrXXX, where XXX the JSR number)
# jdkX (Patches related to supporting jdkX as the host VM, where X the JDK version)
# dbg (Changes in debugging code/frameworks; no production code change)
# license (Edits regarding licensing; no production code change)
# hack (Temporary fix to make things move forward; please avoid it)
# WIP (Work In Progress; for intermediate commits to keep patches reasonably sized)
# defaults (changes default options)
#
# Note: Multiple tags can be combined, e.g. [fix][jsr292] Fix issue X with methodhandles
# --------------------
# Remember to:
# * Capitalize the subject line
# * Use the imperative mood in the subject line
# * Do not end the subject line with a period
# * Separate subject from body with a blank line
# * Use the body to explain what and why vs. how
# * Can use multiple lines with "-" or "*" for bullet points in body
# --------------------
Note that #
is comment-out, so we do not have to delete everything.
To tell Git to use the template file (globally, not just in the current repo), use the following command:
$ git config --global commit.template ~/.github/.gitmessage
To customize the editor (e.g. emacs, vim) for commit message, use the following command:
$ git config --global core.editor <editor name>
[References]
- Using Git commit message templates to write better commit messages
- How to write a git commit message
- One example of git commit message template
- 8.1 Customizing Git
These rules are helpful for both contributors and reviewers, because they make the PR procedure smoother and quicker. We recommend to look at your codes once more to check if they are already easier to review.
- Make it small (split PR within a small number of files)
- Do only one thing
- Add documentation string (Google python docstrings) and code explanations
- Add tests
- Push as soon as possible and do not keep changes only in your local repository
- Separate refactoring from features
Note that we prefer code explanations in the actual codes rather than PR comments, because they should not be used only for temporal explanations. However, it is also promoted to put comments on the Github webpage for the PR to dispel reviewers' doubt beforehand.
For the optional strategies, it is recommended to follow:
- Make PRs for each small change when you would like to change small issues across many files such as changing variable names
- Units first, integration later (new PRs for each unit)
[References]
- 10 tips for better Pull Requests
- The (written) unwritten guide to pull requests
- PULL REQUEST GUIDELINES
- Pull Request Etiquette - A set of simple rules for your code review
- The Art of Small Pull Requests
- How to Split Pull Requests – Good Practices, Methods and Git Strategies
To recall what to write in PRs and issues, put pull_request_template.md
and issue_template.md
in the home directory.
The example templates are available in the references.
[References]
- A Github pull request template for your projects
- Github templates: The smarter way to formalize pull requests among development teams
- 10 examples of issue templates
- A practical guide to small and easy-to-review pull requests
- cancel the staging of the file
$ git reset HEAD <file name>
- Check the commit history (option: -p, --stat, --graph, --oneline, -)
$ git log
or
$ git log origin/<branch name>
- Check the differences between branches, files and so on (option: --cached, --name-only, --stat, --word-diff)
$ git diff <target1> <target2>
- Check who changed the file (option: -e, -f, -n)
$ git blame <file name>
Useful when you try to contact the person for the discussion or the intention behind the code
- git rebase usage Cancel the rebase
$ git rebase --abort
Continue the rebase (Use it when conflicts happen)
$ git rebase --continue
Group a bunch of commits (We can check ID by git log.)
$ git rebase -i <group commits after this ID>
- Escape the current changes
# escape the current changes
$ git stash
# Recover the escaped changes
$ git stash apply
# Clear the escaped changes (Check if the changes are really recovered before using this command.)
$ git stash clear
- Check the base branch of the current branch
$ git show-branch | grep '*' | grep -v "$(git rev-parse --abbrev-ref HEAD)" | head -1 | awk -F'[]~^[]' '{print $2}'
- Find files that have a specific sentence
# We can use wild card "*" for file name
$ find -name “<file name>” -exec grep "<target sentence>" {} \; -print