Git
Also check out Git
If you are just starting answer the following questions in a text document by searching and watching YouTube videos
- How do I install git
- How do I set name and email
- How to I update name and email
- How do I clone a git repo
- How do I use Git via HTTPS
- How do I use Git via SSH
- What is the pro and con to using Git via HTTPS verses SSH
- How do I add and stage files in order to make a commit
- How can I add individual files
- How can I add all files in a directory
- What is git pull and what does it do
- How do I make a commit
- How do I make a branch
- How do I list the branches I have
- How do I change branches
- How do I merge a branch*
- This one can be complicated, just learn the basics
- What is git push
- How to I select which branch to push to
- How do I which remote repository to push to
- What is a Pull Request
- Where do I find pull requests?
- How do I submit a pull request
Reset name and email
git config --global -e
Reset branch to head and delete unused files
git reset --hard HEAD
# Delete all unused files
git clean
git clean -f
Force Git Push
git push origin <your_branch_name> --force
Revert history of remote Git repository
git reset --hard commit_hash
git push https://git.... --force
Change text editor
# Change text editor
git config --global core.editor "nano"
git config --global core.editor "vim"
Changing Names of Branches
Changing a remote branch name
# list all remote branches
git fetch
git branch -a
# Changing a Remote Branch
git remote -v
git remote add <remote_name> <remote_url>
git remote rename <old_name> <new_name>
git remote remove <name>
Delete local and remote branch separately
# local
git branch -d feature/login
# remote
git push origin --delete feature/login
Delete a local and a remote GIT branch
git branch -D branch_name
git push <remote_name> --delete <branch_name>
Advanced Tricks
# Skip `git add .`
git commit -am "git commit message"
# Check git config
git config -e
git config --global -e
# Local git config
# Change previous commit before push
git commit --ammend
git commit --ammend --no-edit
# Force local code to remote branch
git push origin master --force
# Go back to previous commit but keep history
git revert <branch or commit hash>
# Save stuff for later locally without creating a separate branch
git stash
git stash pop
git stash save stashname
git stash list
git stash apply stashname
# Rename a branch
git branch -M new_name
# Better git log
git log --graph --oneline --decorate
# How do I got back one commit at a time without having to checkout
git bisect start
# bad
# good
# How do I compress commits
git rebase master --interactive
# popup, replace pick with `squash` to keep comment in logs or `fixup` to remove comment for what you want to merge into a single commit
git commit --fixup commit_hash
git commit --squash commit_hash
git rebase -i --autosquash
# git hooks, scripts trigged by git
# inside .git/hooks
# https://www.npmjs.com/package/husky
# Fuck my code and reset everything
git reset --hard HEAD
git clean -df
# Checkout previous branch
git checkout -
Git submodules
# Add
git submodule add {ssh or https path to git repo}}
# pull / Update
git submodule update --recursive --remote
- References:
- Add a submodule
- https://stackoverflow.com/questions/1030169/pull-latest-changes-for-all-git-submodules
Pull all branches
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all
Links
Sources
- 13 Advanced but useful Git Techniques and Shortcuts - YouTube
- How to ammend last commit
- How to List Remote Branches in Git – TecAdmin
- How to remove local untracked files from the current Git branch | by Aram Koukia | Koukia
- How To Git Reset to HEAD – devconnected
- Rename a local and remote branch in git – Multiple States Knowledge Base
- How do I properly force a Git push? - Stack Overflow
- git pull fails "unable to resolve reference" "unable to update local ref" - Stack Overflow
- How can I delete a remote branch in Git? | Learn Version Control with Git
- Delete a local and a remote GIT branch | by Aram Koukia | Koukia
Git Research
Initializing Keybase... done.
Syncing with Keybase... done.
hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint:
hint: git config pull.rebase false # merge
hint: git config pull.rebase true # rebase
hint: git config pull.ff only # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.
git commit --date="1 hours ago" -m "message"
- How can one change the timestamp of an old commit in Git? - Stack Overflow
- Pull latest changes for all git submodules - Stack Overflow
- How can one change the timestamp of an old commit in Git? - Stack Overflow
- github - Use future date while making git commits - Stack Overflow
git commit --amend --date="Jan 24 22:02 2023 +0500" --no-edit
- Git: Easiest way to reset git config file - Stack Overflow
- git config --global url."https://github.com/".insteadOf
- github - Git merge with force overwrite - Stack Overflow
- git - How do I view all commits for a specific day? - Stack Overflow
- version control - How can I get a list of Git branches, ordered by most recent commit? - Stack Overflow
- How to merge two or multiple git repositories into one | by Vaibhav Mule | AltCampus | Medium
- How to Merge Two Git Repositories
- get number of git commits
- version control - How do I undo the most recent local commits in Git? - Stack Overflow
- version control - Git: How do I force "git pull" to overwrite local files? - Stack Overflow
- How can I make Git "forget" about a file that was tracked, but is now in .gitignore? - Stack Overflow
- Cheatsheet
- [13 Advanced (but useful|[but useful|[but useful|[but useful|[but useful|but useful|[but useful|[but useful|[but useful|[but useful) Git Techniques and Shortcuts - YouTube](../but useful) Git Techniques and Shortcuts - YouTube]] Git Techniques and Shortcuts - YouTube](but%20useful) Git Techniques and Shortcuts - YouTube Git Techniques and Shortcuts - YouTube]]%20Git%20Techniques%20and%20Shortcuts%20-%20YouTube)
- git - How to revert pushed commits? - Stack Overflow
- Read through all the example below and better organize them
- Put this in the skill tree
- OpenSSH update causes problems : archlinux
- How To Clear Git Cache – devconnected
- What is git stash?
- Pulling from Git fails and gives me following error: client_global_hostkeys_private_confirm: server gave bad signature for RSA key 0 - Stack Overflow
- List all developers on a project in Git - Stack Overflow
wiki.software.List.ssh
Remote Branches
# list all remote branches
git fetch
git branch -a
https://tecadmin.net/list-all-remote-branches-in-git/
Rename local and remote
https://multiplestates.wordpress.com/2015/02/05/rename-a-local-and-remote-branch-in-git/
Delete local and remote branch separately
# local
git branch -d feature/login
# remote
git push origin --delete feature/login
Pull all branches
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done
git fetch --all
git pull --all
Delete a local and a remote GIT branch
git submodules
# Add
git submodule add {ssh or https path to git repo}}
# pull / Update
git submodule update --recursive --remote
- References:
- Add a submodule
- https://stackoverflow.com/questions/1030169/easy-way-to-pull-latest-of-all-git-submodules
Restore a delete file
Delete file form hit history
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch path_to_file" HEAD
-
git commit - Purging file from Git repo failed, unable to create new backup -...
-
References
- github - How to remove file from Git history? - Stack Overflow
- git commit - Purging file from Git repo failed, unable to create new backup - Stack Overflow
Reset branch to head
git reset --hard HEAD
# Delete all unused files
git clean
git clean -f
- References:
- How To Git Reset to HEAD – devconnected
Delete untracked files
git clean -n
git clean -f
- References:
- How to remove local untracked files from the current Git branch | by Aram Koukia | Koukia
git pull fails "unable to resolve reference" "unable to update local
Revert to previous commit
git reset --hard COMMIT HASH
git push https://git.... --force
- References:
- git pull fails "unable to resolve reference" "unable to update local ref" - Stack Overflow
For push
git push origin <your_branch_name> --force
Amend
- References:
- How to ammend last commit
npm install -g ts-node typescript '@types/node'
npx ts-node typescript-file.ts