TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Learn Git Branching

259 pointsby dsego9 months ago

17 comments

l5870uoo9y9 months ago
I have these Git shortcuts stored in my .zshrc file:<p># <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;4298960&#x2F;git-add-a-git-commit-in-one-command" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;4298960&#x2F;git-add-a-git-co...</a><p>git config --global alias.ac &#x27;!git add -A &amp;&amp; git commit&#x27;<p>git config --global alias.acm &#x27;!git add -A &amp;&amp; git commit -m&#x27;<p>git config --global alias.ll &#x27;!git log --graph --full-history --all --color --pretty=format:&quot;%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s&quot;&#x27;<p>git config --global alias.gst &#x27;!git status&#x27;<p>git config --global alias.gca &#x27;!git commit -a --amend&#x27;<p>git config --global alias.gp &#x27;!git push origin HEAD&#x27;<p>git config --global alias.bd &#x27;!git branch -d&#x27;<p>git config --global alias.bdd &#x27;!git branch -D&#x27;<p>git config --global alias.mc &#x27;!git diff --name-only --diff-filter=U&#x27;<p>git config --global alias.co &#x27;!git checkout&#x27;<p>git config --global alias.po &#x27;!git push origin&#x27;<p>git config --global alias.cp &#x27;!git add -A &amp;&amp; git commit -m &quot;Content&quot; &amp;&amp; git push&#x27;<p>Out of those, I only – but often – use `git acm` and `git co` and `git po`.<p>Edit: formatting (oh dear).
评论 #41548715 未加载
评论 #41554399 未加载
评论 #41548532 未加载
评论 #41550423 未加载
评论 #41551474 未加载
评论 #41549804 未加载
评论 #41565983 未加载
TheHippo9 months ago
Nothing about the content of the site, but please stop determining the language of the user based on geolocation. If the browser says he wants English, serve English.
评论 #41579692 未加载
评论 #41551738 未加载
leetrout9 months ago
I also recommend an alias like this (and l5870uoo9y has other examples and how to set them as git aliases)<p><pre><code> alias gitlg=&quot;git log --graph --all --format=format:&#x27;%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n&#x27;&#x27; %C(white)%s%C(reset) %C(bold white)— %an%C(reset)&#x27; --abbrev-commit&quot; </code></pre> From <a href="http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;1057564&#x2F;pretty-git-branch-graphs" rel="nofollow">http:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;1057564&#x2F;pretty-git-branch...</a>
评论 #41549080 未加载
talkingtab9 months ago
I&#x27;m one of those &quot;I don&#x27;t want to read the manual&quot; people and have long used git. However, this was very helpful to easily understand some cargo-cult things I was doing. Shame on me! And thank you!
actinium2269 months ago
It seems whenever I show someone this site, they&#x27;re like &quot;oh this is cool!&quot; and never look at it again.<p>I wonder if there&#x27;s something about it that makes it forgettable? I don&#x27;t know if I can present it any differently, maybe there&#x27;s a better way of presenting it to make it more appealing.
评论 #41553517 未加载
评论 #41558136 未加载
cryptonector9 months ago
Git _is_ branching. Every clone is a[n unpublished] branch.
评论 #41548614 未加载
评论 #41549610 未加载
hnuser1234569 months ago
Why do the arrows point backwards? (I get it points to the parent, but I&#x27;d rather point forward chronologically, any commit history viewers that allow this?)
评论 #41552035 未加载
neves9 months ago
This is an excellent resource. The animations really help to understand Git concepts. I successfully used it for an internal Git course.
codingminds9 months ago
Sadly I&#x27;m not able to enter any command. Even after disabling the ad blocker
评论 #41553512 未加载
评论 #41554436 未加载
srameshc9 months ago
This is really great resource for someone getting started to understand what&#x27;s going on. I see many have issues and try out different git commands without understanding the outcome.
评论 #41548360 未加载
评论 #41548667 未加载
评论 #41548868 未加载
lainga9 months ago
Has anyone used `git describe` in anger?
评论 #41551462 未加载
sakesun9 months ago
I&#x27;ve finished all levels of the tutorial several times. Yet when in real work, I&#x27;m still often struggle with git. :(
kwar139 months ago
Love this tutorial. Thanks!
Gepsens9 months ago
Sharing a few of my own :<p># <a href="https:&#x2F;&#x2F;github.com&#x2F;Igosuki&#x2F;dotfiles&#x2F;blob&#x2F;master&#x2F;git&#x2F;.gitconfig">https:&#x2F;&#x2F;github.com&#x2F;Igosuki&#x2F;dotfiles&#x2F;blob&#x2F;master&#x2F;git&#x2F;.gitconf...</a><p>grep = grep -Ii<p>lalias = &quot;!git config -l | grep alias | cut -c 7-&quot;<p>done = &quot;!f() { git branch | grep &quot;$1&quot; | cut -c 3- | grep -v done | xargs -I{} git branch -m {} done-{}; }; f&quot;<p>assumed = &quot;!git ls-files -v | grep ^h | cut -c 3-&quot;<p>lasttag = describe --tags --abbrev=0<p>lt = describe --tags --abbrev=0<p>dr = &quot;!f() { git diff &quot;$1&quot;^..&quot;$1&quot;; }; f&quot;<p>lc = &quot;!f() { git ll &quot;$1&quot;^..&quot;$1&quot;; }; f&quot;<p>diffr = &quot;!f() { git diff &quot;$1&quot;^..&quot;$1&quot;; }; f&quot;<p>lb = &quot; !f() { git branch -a | more; }; f&quot;<p>cp = cherry-pick<p>st = status -s<p>cl = clone<p>ci = commit<p>br = branch<p>diff = diff --work-diff<p>dc = diff --cached<p>r = reset<p>r1 = reset HEAD^<p>r2 = reset HEAD^^<p>rh = reset --hard<p>rh1 = reset --hard HEAD^<p>rh2 = reset --hard HEAD^^<p>sl = stash list<p>sa = stash apply<p>ss = stash save<p>logtree = log --graph --oneline --decorate --all<p>lmine = &quot;!f() { git log --branches --author=igosuki@gmail.com; }; f&quot;<p>purgeforever = &quot;!f() { git filter-branch --prune-empty -d &#x2F;dev&#x2F;shm&#x2F;scratch --index-filter &quot;git rm --cached -f --ignore-unmatch $1&quot; --tag-name-filter cat -- --all }&quot;<p>updaterefsafterpurge = &quot;f() { git update-ref -d refs&#x2F;original&#x2F;refs&#x2F;heads&#x2F;master; git reflog expire --expire=now --all; git gc --prune=now }&quot;<p>ec = config --global -e<p>up = !git pull --rebase --prune $@ &amp;&amp; git submodule update --init --recursive<p>cob = checkout -b<p>cm = !git commit -m<p>save = !git add -A &amp;&amp; git commit -m &#x27;SAVEPOINT&#x27;<p>wip = !git add -u &amp;&amp; git commit -m &quot;WIP&quot;<p>undo = reset HEAD~1 --mixed<p>amend = commit -a --amend<p>wipe = !git add -A &amp;&amp; git commit -qm &#x27;WIPE SAVEPOINT&#x27; &amp;&amp; git reset HEAD~1 --hard<p>bclean = &quot;!f() { git branch --merged ${1-master} | grep -v &quot; ${1-master}$&quot; | xargs -r git branch -d; }; f&quot;<p>bdone = &quot;!f() { git checkout ${1-master} &amp;&amp; git up &amp;&amp; git bclean ${1-master}; }; f&quot;<p><pre><code> pr = pull --rebase </code></pre> I&#x27;d advise binding things like pr, po, cp, --rebase, --continue, to keyboard shortcuts though if you are in an IDE.
dev1ycan9 months ago
great tutorial!
mediumsmart9 months ago
excellent tutorial, thank you for that.
DavidWoof9 months ago
One of my biggest pet peeves about modern development is just how many people don&#x27;t know jack about git even though they use it every day. It really annoys me when I see a pull request with 20 random commits (with messages like &quot;temp&quot; or &quot;checkpoint&quot;) or when people merge main into their personal feature branch instead of just rebasing their branch (yes, sometimes that&#x27;s not right, but I&#x27;m not talking about the corner cases).<p>I always think about using &quot;clean up a pull request&quot; as a fizzbuzz-ish screen in interviews. It just seems like a decent proxy for &quot;do you care at all?&quot;.
评论 #41552062 未加载
评论 #41554252 未加载
评论 #41554370 未加载
评论 #41551189 未加载
评论 #41554428 未加载
评论 #41554530 未加载
评论 #41553621 未加载
评论 #41554526 未加载
评论 #41551240 未加载
评论 #41554350 未加载
评论 #41557585 未加载
评论 #41554825 未加载