Monday, September 27, 2021

Git unplugged notes

Git unplugged notes

Rebase issue

# If someone rebases on public branch, after pull all others could see:

Your branch and 'origin/branch1' have diverged,

and have 2 and 3 different commits each, respectively.


git fetch origin

git reset --hard origin/main

src stackoverflow

Rebase issue

Your branch is ahead of 'origin/master' by 3 commits


git fetch -p # clean up local branches

git pull --rebase # pull and rebase my local commits on top of incoming

Better solution (unchecked)

Step 1 : git checkout branch1

Step 2 : git pull -s recursive -X theirs # merge strategies

Step 3 : git reset --hard origin/branch1

Rebase issue explained (long)

git rev-list --count --left-right branch1...upstream

git rev-list --count --left-right origin/master...HEAD


# to see if the local repository is ahead, push needed:

git rev-list origin..HEAD

# to see if the local repository is behind, pull needed:

git rev-list HEAD..origin

# if you have numbers for both, then the two repositories have diverged:

git rev-list --count --left-right origin/master...HEAD

src: stackoverflow



# squash - reset soft:

#git reset --soft master

git reset --soft origin/master

git add -A

git commit

git push --force

# squash - reset to merge-base:

git checkout branch1

git reset $(git merge-base master $(git branch --show-current))

git add -A

git commit

git push --force

# src:

# Note: git merge-base branch2 branch3


# squash - merge squash:

git checkout origin/master

git merge --squash origin/branch1

git commit

git push --force

Git branch_name vs refs

git show-ref origin/main

1. If $GIT_DIR/<refname> exists, that is what you mean (this is usually useful only for HEAD, FETCH_HEAD, ORIG_HEAD, MERGE_HEAD and CHERRY_PICK_HEAD);

2. refs/<refname> if it exists;

3. refs/tags/<refname> if it exists;

4. refs/heads/<refname> if it exists;

5.  refs/remotes/<refname> if it exists;

6. refs/remotes/<refname>/HEAD if it exists.


Long aside: how this all works (read only if sufficiently curious) :


Git server repository (docker git repo)

Alpine Git client

JKarlos Docker Git server

Gogs and Podman Git server

Gogs Git server

Gogs by Pirates - GitHub like Git server

Gitea in Docker - demo - github

GitColony docker server - obsolete

Git server:

Google it:

Git server list - wiki:





Wiki says: External projects like gitolite, which provide scripts on top of git software to provide fine-grained access control.




Gitea = fork of Gogs

Git Web interface self-hosted:

Options – list – good overview:

GitLab = web git, “Confluence” wiki, “Jira” tracker

Gitea – community fork of Gogs:

Savannah = GNU = free software foundation (FSF)

GitBucket – Open source

Gogs - self hosted Git:


Awesome Selfhosted:



Git web UI – including proprietary and closed-source:

No comments: