Skip to content

Git notes

Using git for version control. Lessons learned.

How To

  • Git tag
    1. Adding a tag
      • git tag v1.0
      • git push origin --tags - push to github
    2. Deleting tags
      • git tag -d v1.0
      • git push origin :refs/tags/v1.0
    3. Get all tags including remote tags
      • git fetch --all --tags --prune - get all remote tags and remove repos removed by remote.
    4. Need tags for composer
  • git worktree Git Worktree
    • Create temporary checkout for working on a branch without having to stash data
  • Delete local and remote branches
    git push -d <remote_name> <branch_name>
    git branch -d <branch_name>
  • Update local list and prune branches
    • git fetch -p -p is for prunining

Git Resources


Git error message. Can’t merge unrelated histories.

  • Allow unrelated histories StackOverflow Issue
  • git pull remote branch --allow-unrelated-histories

Git error trying to push when pull seems to work

hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
* Hint: Read hints * Checkout out rejected branch. git checkout master * git pull {remote} master --allow-unrelated-histories * Fix conflicts and commit * git push {remote} master

Removing sensitive data from git after having committed Removing Sensitive Data - Github

  • git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch {path/filename}' --prune-empty --tag-name-filter cat -- --all
  • git push github --force --all
  • Remove the references
  • git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin
  • git reflog expire --expire=now --all
  • git gc --prune=now

  • No guarantee that the data hasn’t been downloaded or forked but at least it’s removed going forward.

Git create empty branch

  • Create Orphan Branch
  • Steps:
    1. git checkout --orphan NEWBRANCH
    2. git rm -rf .
    3. git remote add {name} {git remote branch}
    4. git pull -u {name} {branch}
    5. git push -u {name} {branch}
  • Now one have a copy of another branch in working branch.

Github Markdown

Remote branches not showing on local. Only shows master.

  • git branch -a show all branches
  • git checkout --track remote/branch - pulls in the remote branch.

Unrelated histories

  • git pull --allow-unrelated-histories

Last update: April 13, 2020 16:50:19