-
Notifications
You must be signed in to change notification settings - Fork 6
Git Rebase Workflow
A Git rebase workflow is a strategy for managing changes in a Git repository that involves incorporating changes from one branch into another by reapplying the commits from the source branch onto the target branch. This creates a linear history and helps keep the commit history cleaner. It's commonly used for feature branches to keep the main branch up to date with the latest changes.
It's highly recommended to use the terminal for most git actions. GitHub desktop isn't recommended due to being much slower on various actions required repeatedly by this process.
Fork the Repository:
- Go to https://github.com/MediEvilDecompilation/medievil-decomp.
- Click the "Fork" button on the top right. This creates your own copy of the repository under your GitHub account.
- Note that by default you'll only fork main, so you may want to uncheck the box to fork all branches.
Clone Your Fork:
- On your GitHub profile, open the forked repository.
- Click the "Code" button and copy the URL of your forked repository.
- Open your terminal and use the following git command:
git clone https://github.com/<YOUR_USERNAME>/medievil-decomp.git
Create a New Branch:
- You'll by default be checkout
main
- Use
git checkout -b new-feature
to create and switch to a new branch (replace "new-feature" with your branch name).
Make Changes:
- Make the desired changes to your code in the new branch.
Commit Changes:
- Use
git add .
to stage all your changes or you could use a git UI such as the one built into Visual Studio Code for specific files. - Use
git commit -m "Description of your changes"
to commit your changes to the branch.
Push Changes to Your Fork:
- Use
git push
to push your changes to your fork on GitHub.
Create a Pull Request (PR):
- Go to your fork's GitHub page.
- Click the "Pull Requests" tab and then "New Pull Request."
- Choose the base branch, which is typically MediEvilDecompilation/medievil-decomp's main branch.
- Choose your fork's branch as the compare branch.
- Add a title and description for your PR and then click "Create Pull Request."
Rebase Your Changes (Git Rebase Workflow):
- If your PR falls behind the main repository due to other changes, you can update your fork with the latest changes from the main repository:
- Add the main repository as a remote using
git remote add upstream https://github.com/MediEvilDecompilation/medievil-decomp.git
. - Fetch the latest changes from the main repository with git fetch upstream. For ease, we recommend
git fetch --all
. - Switch to your branch with
git checkout new-feature
. - Use
git rebase upstream/main
to rebase your changes onto the latest main branch. - Push the rebased changes with
git push --force-with-lease
.
Review and Merge:
- Your PR will be reviewed by project maintainers.
- If approved, it can be merged into the main repository.
It's highly recommended from this point forward that once setting the upstream remote (and by default having your origin remote) to always start your day by fetching all and rebasing your origin main against upstream/main to avoid lots of conflicts.
If when trying to rebase you encounter lots of conflicts, you will either need to address them all a step at a time (see below) or can abort the rebase process by typing git rebase --abort
. If you abort, you could try merging upstream/main into your current branch to see if it updates refs successfully. To deal with the conflicts, however...
Look carefully at the various conflicts in your files, see which one you should accept as "true". Perhaps it's bringing in garbage that's now incorrect due to a few changes that you fixed 5 commits ago? You could try copy/pasting the "correct" info each time, or going through the process each step of the rebase process. To continue using the command line, it's git rebase --continue
, though we recommend using the Git UI built into Visual Studio Code for this issue.
If you need help with this process, feel free to ask on the Discord server! It can be a little confusing at first but it's a great workflow!