DEV Community

Patrick Wendo
Patrick Wendo

Posted on

Let's learn together.

I propose a let's learn thread where you post a topic you consistently find hard and the guys in the comments help you understand it better.

I start by mentioning that sometimes git checkout -b and setting up a new git branch to track a remote branch usually confuses me. I always have to Google how to do it. Even if I think I understood it last time. Is there a way you learned and understood this particular set of git commands?

Top comments (6)

Collapse
 
jeremyf profile image
Jeremy Friesen

For a long-time, I've defaulted to tracking branches. In 2.37.x (maybe 2.37.1) they introduced the following git config: git config --global push.default current. Now, whenever you "push" you create a tracking branch.

Underlying all of this is to create git functions that are aliases of the behavior I want.

I have a shell script name git-author-count with the following body:

#!/bin/sh

git shortlog -se $@ | sort -r
Enter fullscreen mode Exit fullscreen mode

Now, I can run git author-count (note that the - between git and author-count is gone). Why is that? Because if I have an executable script prefixed with git- in my $PATH, I can then use git <suffix> to run that command.

The $@ is "all of the arguments I passed to git author-count".

My dotzshrc bin directory has a lot of things. I also have several git aliases

Collapse
 
w3ndo profile image
Patrick Wendo

Your dotzshrc is wayyyy bigger than mine. Pretty impressive

Collapse
 
jeremyf profile image
Jeremy Friesen

I do have a few more years on you to accumulate some cruft.

Thread Thread
 
w3ndo profile image
Patrick Wendo

That is true.

Collapse
 
ben profile image
Ben Halpern

I start by mentioning that sometimes git checkout -b and setting up a new git branch to track a remote branch usually confuses me. I always have to Google how to do it.

I'm curious — do you find that it is the command you can't remember or the "concept" you have a hard time remembering?

Collapse
 
w3ndo profile image
Patrick Wendo

It's the command. Cause I typically know what to search for to get the command, but I can never remember the command.