Keeping your repository up to date - RedHatInsights/red-hat-ansible-automation-platform-documentation GitHub Wiki
When you are working with a team on a repository, it is important to keep your work in sync with the upstream repository.
-
Navigate to the branch that you want to sync with upstream.
git checkout <tracked_branch>
-
Fetch all commits from upstream.
git fetch upstream
-
Run
git rebase
to incorporate the commits from upstream/<tracked_branch> into your local branch. Do not usegit pull
, as it adds extra commits.git rebase upstream/<tracked-branch>
-
Push your local branch to your forked repo.
git push origin <tracked-branch>
The following example syncs your local main
branch with the upstream/main
branch:
$ git checkout main $ git fetch upstream $ git rebase upstream/main $ git push origin main
As you work on your topic branch, it is important to incorporate new commits from the upstream parent branch.
Before you begin:
-
Run
git status
to check whether you have uncommitted changes on the topic branch; rungit commit
to save them. -
Optional steps:
-
To get an idea of how much work the rebase will entail, run
git log --oneline -n 5 <topic_branch>
andgit log --oneline -n 5 <upstream/parent_branch>
, or view the parent branch on GitHub. If your topic branch and new parent branch commits both involve changes to the same files, you may need to resolve a conflict. -
Back up your topic branch by pushing it to your forked repo. This is useful if you have trouble resolving a snarly conflict.
-
Identify the parent branch
-
If you created your topic branch by branching from
main
, rebase upstream changes to main with your topic branch. -
If you created your topic branch by branching from a release branch, rebase changes to the upstream release branch with your topic branch.
-
If you created your topic branch by branching from an upstream feature branch, you must rebase changes in the upstream feature branch with your topic branch.
Rebase commits from the parent branch onto the topic branch
-
Checkout your local topic branch
git checkout <topic_branch>
-
Retrieve new changes from upstream
git fetch upstream
-
Rebase upstream changes to the parent branch with your local branch
git rebase upstream/<parent_branch>
-
If there are no conflicts, git reports the status of the topic branch after the successful rebase.
$ git rebase upstream/main First, rewinding head to replay your work on top of it... Applying: Update attribute values for operator components
-
If there are conflicts, the message from git includes
CONFLICT
. Refer to Resolving conflicts for details.$ git rebase upstream/main First, rewinding head to replay your work on top of it... Applying: Update operator planning procedure CONFLICT (content): Merge conflict in downstream/modules/operator-planning.adoc Failed to merge in the changes. Patch failed at 0035 Update operator planning procedure
-
-
Push the changes to to your forked repo.
git push origin <topic_branch>