Git protip: easy templates for `.gitignore`
The .gitignore file is great! But it can be tedious to fill in. What if we could do it all in one go?
Git is packed with a whole bunch of commands and options, and the range of possible uses is vast. Here are a few tips drawn from many years of expertise as users and trainers.
The .gitignore file is great! But it can be tedious to fill in. What if we could do it all in one go?
Resolving conflicting files after a merge can be time consuming. Fortunately Git provides us with a tool to speed this up!
No more explicit branch tracking on push! Say hello to autoSetupRemote configuration!
Did you know that you could force the push without risking to erase your collegues work?
Do you make typos when writing your commands? Would you like Git to correct automatically?
What about an alias that would to the job for you?
You can quickly "update" an old commit thanks to "commit --fixup"
Use "git log -L" to track changes only within a code block, figure out who actually introduced a bug, etc.
Do you think "git blame" is a good idea? You’re wrong!
You just screwed up your last commit and want to fix it? The "git commit --amend" command is your friend!
The classic Git log (for displaying the commit history) does not fit the standard use case. Rather than using a graphical interface, let’s use an alias and a custom log.
See differences in files, line by line, without any visual pollution
Oh boy, are branches great. They let you have entirely different versions of a given file, depending on the context. The thing is, in a few (not so rare) situations, you may want to version a file that changes from branch to branch, but retain its current content when merging another branch into yours.
So you fixed a conflict somewhere in your repo, then later stumbled on exactly the same one (perhaps you did another merge, or ended up rebasing instead, or cherry-picked the faulty commit elsewhere…). And bang, you had to fix that same conflict again. That sucks.
You think you know Git? Maybe you do… And yet, I’d bet my shirt that many cool little command-line options remain unknown to you.