Git - atabegruslan/Notes GitHub Wiki

Git moves and solutions to common issues

Restore deleted repo

https://docs.github.com/en/repositories/creating-and-managing-repositories/restoring-a-deleted-repository#restoring-a-deleted-repository-that-was-owned-by-a-personal-account

Embedding various things

Multiple GitHub account issues

Auth

Commit with different credentials

git -c user.name="{USERNAME}" -c user.email={EMAIL} commit -m "commit message" --author="{USERNAME} <{EMAIL}>"
git remote add origin https://github.com/{USERNAME}/{REPO}.git

Syncing existing code to existing repo

git pull origin master --allow-unrelated-histories

Git submodule

In the dependant repo: git submodule add -b develop https://username:[email protected]/account/needed-project dest-path/needed-project In the terminal: git submodule init && git submodule update

Undo

Via Revert

Revert a specific commit: git revert {commit hash ID}

Revert previously pushed commit (locally, ie: Undo previous commit):

git checkout HEAD~1 (local go back 1), git reset --hard origin/branchName, git checkout branchName (make sure still on right local branch), git pull (make sure up to date)

Revert previously pushed commit (remotely):

git log get commit hash, git revert xxx or git revert HEAD-1..HEAD (go back 1), update commit message, git push

Un-Revert

Via Reset

Locally

Undo previous commit:

git reset --soft HEAD~1
# Make changes
git commit -c ORIG_HEAD # use previous commit & commit message
# Update commit message if you want

Undo git add README.md: git reset README.md

To Remote Repo

Via Checkout

git checkout {commit hash} .
git commit -m"xxx"

Via Patch

Cherrypick

Applying a commit to a branch from another branch

git checkout {dest branch}
git cherry-pick {src commit SHA}

Rebase

Don't rebase any commits that's been pushed to a remote repo

Stash

  1. Save changes to branch A.
  2. Run git stash.
  3. Check out branch B.
  4. Fix the bug in branch B.
  5. Commit and (optionally) push to remote.
  6. Check out branch A
  7. Run git stash pop to get your stashed changes back.

Log

Git Terminology

Inner Workings

Useful commands

GitBook

https://github.com/atabegruslan/Notes/tree/main/notes/git/gitbook_win

Working with private Git repos may only work with SSH

Grepper

⚠️ **GitHub.com Fallback** ⚠️