Differences between revisions 6 and 7
Revision 6 as of 2021-05-13 14:26:07
Size: 2319
Comment:
Revision 7 as of 2022-09-12 17:40:35
Size: 2542
Comment:
Deletions are marked like this. Additions are marked like this.
Line 45: Line 45:
== Maintaining Local Branches or Forks == == Rebasing Forks ==
Line 76: Line 76:
If there is an issue with a rebase, try:

{{{
git reflog
git reset --hard $COMMIT_PRIOR_TO_REBASE
}}}

For example, if the commit prior to a rebase was `HEAD@{2}`, the correction for a bad rebase would be `git reset --hard HEAD@{2}`.

Git Branches

One of the particular strengths of git(1) as a versioning software is its concept of branches. Each branch is an independent collection of commits, with no real need for centralized management. Branches have discreet points of divergence that can be reconciled if needed.


Renaming Branches

A local-only branch can be renamed easily. Given a repository named my-repo:

# ensure that you are in the repository directory and checked into the target branch
cd path/to/my-repo
git checkout master

# to rename branch 'master' to 'dev'...
git branch -m master dev

To rename a remote branch, first follow the above process. The remaining steps can produce errors.

git push -u origin dev
git push origin --delete master

If git returns an error like  ! [remote rejected] master (deletion of the current branch prohibited), then you need to adjust the HEAD of the remote repository. This determines what branch a new repository clone will start on. The 'default' branch cannot be deleted for obvious reasons.

Keeping with the example above, access the bare remote repository my-repo.git and edit my-repo.git/HEAD such that it points to the new branch's head.

ref: refs/heads/dev

Valid values correspond to the branch references in my-repo.git/refs/heads/.


Rebasing Forks

Best practice is to manage local changes in a separate branch. This will make it easier to merge upstream commits while maintaining your own.

After fetching or pulling updates, you will be some number of commits behind or ahead (respectively). To throw out local commits, use git reset --hard origin/master.

Then switch to your local branch and begin rebasing it. This process is visualized by upstream documentation as going from...

          A---B---C topic
         /
    D---E---F---G master

...to...

                  A'--B'--C' topic
                 /
    D---E---F---G master

To execute a rebase, try:

git checkout your-local-branch
git rebase master

With any luck, there will have been no conflicts and you will be all set.

If there is an issue with a rebase, try:

git reflog
git reset --hard $COMMIT_PRIOR_TO_REBASE

For example, if the commit prior to a rebase was HEAD@{2}, the correction for a bad rebase would be git reset --hard HEAD@{2}.


CategoryRicottone

Git/Branches (last edited 2023-10-11 14:03:04 by DominicRicottone)