Some Git Resources I Found Usefull on the Internet
Lets start with a joke.
Been there, done that, but u think I think it’s time to get better at Git.
I have a habit of scavenging resources online, took me days. The good thing is I have a collection of useful blogs which I can refer to for non-git info too. This post is for personal consumption. Git commands will be added as I use them more often
Git commands:
git create branch
git force pull
git remove untracked file
git unstage
git undo merge
git remove file
git uncommit
git diff between branches
git delete tag
git rename branch
git show 95fed84 article.md
git log --oneline
git log --oneline --decorate --all --graph
git diff article.md > article_diff.diff
git switch -
#I then clean up the commit series with “git rebase -i” (or if it is a single commit I can instead use just “git commit --amend“).
#Pushing remote reference to local
git push . origin/main:main
# https://myme.no/posts/2023-01-22-git-commands-you-do-not-need.html
#Note: git pull is git fetch followed by git merge
Git commit
Here’s a model Git commit message:
Capitalized, short (50 chars or less) summary
More detailed explanatory text, if necessary. Wrap it to about 72 characters or so. In some contexts, the first line is treated as the subject of an email and the rest of the text as the body. The blank line separating the summary from the body is critical (unless you omit the body entirely); tools like rebase can get confused if you run the two together.
Write your commit message in the imperative: “Fix bug” and not “Fixed bug” or “Fixes bug.” This convention matches up with commit messages generated by commands like git merge and git revert.
Further paragraphs come after blank lines.
-
Bullet points are okay, too
-
Typically a hyphen or asterisk is used for the bullet, followed by a single space, with blank lines in between, but conventions vary here
-
Use a hanging indent
Git checkout vs switch, restore
The new commands in the house https://www.banterly.net/2021/07/31/new-in-git-switch-and-restore/ https://tanzu.vmware.com/developer/blog/git-switch-and-restore-an-improved-user-experience/
Git log
https://zwischenzugs.com/2018/03/26/git-log-the-good-parts/
Git Rebase
Git rebase should be used when you want to integrate changes from one branch into another while maintaining a linear project history. In other words, it allows you to rewrite the commit history of a branch.
Here are some situations where you might want to use git rebase:
-
To integrate changes from a feature branch into the main branch: Instead of merging the branches, you can rebase the feature branch onto the main branch to maintain a cleaner and more linear commit history.
-
To update your local branch with changes from a remote branch: If you’ve made changes to your local branch and there are new changes on the remote branch, you can rebase your local branch onto the remote branch to incorporate the new changes while keeping your local changes.
-
To fix conflicts between two branches: If there are conflicts between two branches, you can use git rebase to resolve them and create a cleaner and more linear commit history.
It’s important to note that git rebase rewrites the commit history, so it should be used with caution. It’s generally recommended to only use git rebase on local branches that haven’t been pushed to a remote repository yet. Reference
Rebase “downstream” and merge “upstream”
Git Stash
git stash #operates on a LIFO stack of sets of changes
git stash list #shows what’s on the stash
git stash push #pushes to the stash
git stash apply #access changes on the stash
git stash drop #removes changes from the stash
git stash pop #does an apply and a drop
#These default to the most recent item on the stash, to reference another one use stash@{index} where you can determine the index from git stash list
#Some of these have flags which make them more convenient, including: -m message, -p patch, -u include untracked files, -k keep staged changes staged
Git workflows
Git branching
https://martinfowler.com/articles/branching-patterns.html
Mono Repos
https://felixmulder.com/writing/2022/03/12/Monorepos-done-right.html
Git for Solo Dev
https://mikkel.ca/blog/git-is-my-buddy-effective-solo-developer/
Handling Git Conflicts
https://blog.nilbus.com/take-the-pain-out-of-git-conflict-resolution-use-diff3/ https://luppeng.wordpress.com/2020/10/10/when-to-use-each-of-the-git-diff-algorithms/
Keeping a Clean Git History
https://blog.sulami.xyz/posts/cleaning-up-git-history/ https://blog.gitguardian.com/rewriting-git-history-cheatsheet/
Git Tutorials
https://blog.plover.com/prog/git/tips.html https://dev.to/nopenoshishi/understanding-git-through-images-4an1 https://wildlyinaccurate.com/a-hackers-guide-to-git/ https://girliemac.com/blog/2017/12/26/git-purr/ https://bakkenbaeck.github.io/a-random-walk-through-git/
Tools:
Setting up multiple git profiles on a single machine:
- https://phili.pe/posts/configuring-git-for-work/
- https://www.micah.soy/posts/setting-up-git-identities/
- https://benjamincongdon.me/blog/2021/12/07/Branchless-Git/
- https://utf9k.net/blog/conditional-gitconfig/
Advanced Topics:
- https://www.cduan.com/technical/git/
- https://maryrosecook.com/blog/post/git-from-the-inside-out
- https://tekin.co.uk/2020/10/better-git-diff-output-for-ruby-python-elixir-and-more
- https://h2.jaguarpaw.co.uk/posts/git-rebase-conflicts/
- https://blog.nilbus.com/take-the-pain-out-of-git-conflict-resolution-use-diff3/
- https://articles.foletta.org/post/git-under-the-hood/