13 Advanced (but useful) Git Techniques and Shortcuts

13 Advanced (but useful) Git Techniques and Shortcuts

Fireship

2 года назад

884,875 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

paulwillisorg
paulwillisorg - 23.09.2023 19:37

I will still call it master and will encourage others to do so.

Ответить
Brian G
Brian G - 08.09.2023 09:28

You will not woke my git.

Ответить
crazychatting
crazychatting - 02.09.2023 00:21

well, even if you execute "git reset --hard origin/master" you can still revert ALL local changes. "git reflog" is like a step by step history of all actions you were making local, eg. switching branches, stashing, resetting, etc., thatswhy you should never ever delete the ".git" directory ;)

Ответить
Yaron Uliel
Yaron Uliel - 30.08.2023 14:30

I would add `git log -2` to view last 2 commits to your list and `git blame` to see who wrote this stupid line

Ответить
yunikbanda
yunikbanda - 26.08.2023 11:45

Great work 👏

Ответить
Marco Cuauhtli Elizalde
Marco Cuauhtli Elizalde - 25.08.2023 01:56

I'm still waiting for the advanced techniques.
Cool for the Linus T apparition.

Ответить
Fabien C
Fabien C - 23.08.2023 15:36

git commit -am doesn't work. It's a myth

Ответить
Andre Zunino
Andre Zunino - 20.08.2023 18:54

It's master branch all the way. Please don't bow down to this disgraceful generation of snowflakes.

Ответить
Kevin Eaton
Kevin Eaton - 20.08.2023 02:14

Is that period key thing legit?!

Ответить
D
D - 19.08.2023 05:02

`commit -a` is not equal to `add & commit` because it doesn't add untracked files for some inexplicable reason
--force-with-lease is better than just --force because it prevents you from an accidental overwrite of the origin
`stash save` doesn't stash untracked files IIRC

Ответить
Janek Schleicher
Janek Schleicher - 15.08.2023 11:28

Just my opinion on aliases, especially if they only shortcut by some letters like your git commit -am vs git ac:
- It makes it less clear what you do when pair programming
- It makes it harder to copy+paste any commands you did in case of writing a README, put it into Teams/Slack or when pair programming
- It makes it harder to write scripts (you can either unintentionally paste your personal aliases or mix up the original commands as you are not used to them)
- When logging to a remote server or working/troubleshooting a colleagues computer, the aliases aren't their, so you still need to know how to use them and without practice, it's unnecessary complicated. Same is true for writing bash/CICD scripts etc.
- Having shortcuts for commands that do magic (auto committing) is a bit dangerous IMHO (ok. git commit -am doesn't have that big error potential, but still you can add unwanted files to the commit, at worst some containing passwords). If you have to type the full command, there's a better chance your brain switches to full attention mode.
- If you don't want to type unnecessary letters: better use autocompletion (exists for bash, zsh, ...) or use an IDE that still show what's going on in detail (emacs magit, lazygit, ...). Aliases and shortcuts adds complexity, while autocompletion reduces it. If you want to use aliases, prefer to use any more standardized ones (so colleagues could just install them with a simple command, like several zsh plugins and look them up easily).

O.K., most of it is personal opinion, and highly biased based on my work (where I often have to trouble shoot other people's problems), but I certainly wouldn't bring up aliases as first suggestion to work with git :-) - if at any all, as one of the last improvement possibilities ...

Ответить
Peter Arbeiter
Peter Arbeiter - 14.08.2023 21:56

Didn't like the start at all. Don't just use "git commit -a" instead of "git add . ; git commit". As someone else pointed out, they are slightly differnt. Then you're talking about the "-am" flag, but that's not even true. It's two flags combined, "-a" and "-m". This might not matter at all. But it makes you look like someone who doesn't even understand shell commands. Then it get's better and better, although I really ask myself how slow you would have to be at typing so that an alias like "git ac" would make a lot of sense. Of course I use some git config as well, but I prefer to be able to do my basic workflow on any machine without first adding a git alias.

Ответить
calloq
calloq - 14.08.2023 05:27

`git reset —hard` doesn’t delete your changes forever. You can always get them back using `git reflog` and creating a new branch referencing the dangling commit that had your old changes. Just make sure you do it before it’s garbage collected

Ответить
Talvi Sota
Talvi Sota - 12.08.2023 11:15

in git is hard to loose things forever, "git reflog"

Ответить
Talvi Sota
Talvi Sota - 12.08.2023 11:11

"master" is the standard name, first step in git is to rename master back to master if needed

Ответить
Tamertamer Tamer
Tamertamer Tamer - 11.08.2023 10:44

Meanwhile me that uses the github desktop app for almost everything

Ответить
Andrew Gisler
Andrew Gisler - 10.08.2023 05:23

God forbid we use the word master! People are so pathetic.

Ответить
Ethernet
Ethernet - 09.08.2023 17:57

One word: Magit

Ответить
Pierre-Emmanuel TOUCHET
Pierre-Emmanuel TOUCHET - 09.08.2023 01:48

Life is too short to write branchName, use "git rebase - "

Ответить
carrion1234
carrion1234 - 04.08.2023 09:47

when you do an interactive rebase, you can use abbreviations for the operations on the commits, s instead of squash, r instead of reword, d instead of drop

Ответить
Blue Square
Blue Square - 03.08.2023 14:43

The -m flag exists for people who are too afraid of vim and dont know about the $EDITOR shell environment variable.

Ответить
matt skov
matt skov - 30.07.2023 05:15

Best git video in the entire world. Thank you for existing fireship

Ответить
David Thacher
David Thacher - 27.07.2023 22:54

git is a linked list. Force commit is banned on most production repositories. (This may include rebasing.) Professional git has a lot of workflows and styles on it. Most agile software has a workflow on it too: story, issues, design review, code review, test, document, merge, release, etc. Most people are forbidden to push or merge onto master or any release branch. People are generally forbidden from pushing onto develop unless through merge/code review.

Some people hate squashing commits as they believe commits should be numerous and tell a story. This all gets into commenting opinions too. Some people believe many commits allows better regression and cherry picking. However others forbid cherry picking like done in SVN. (Some people have lost control of multiple branches doing this.)

On the first day of first job after college a guy told me do not break the branch (or something related to head) or I will be pissed. All I remember thinking is what a putz. Git when properly used, is used with a process. There should never ever be away for me to break anything. The second job I worked for understood this and actually took the time to show their people how to do this. Not the developers as they had quite a few putzs there. Their production build servers were basically playgrounds for kids, but they hired a guy to fix that. One of the things he brought was git and feature/develop/master/release branches. Trust me if you follow the process this kind of issue should never be possible.

First 35 seconds of this video and all I could think about was that putz.

Ответить
Keivan sf
Keivan sf - 23.07.2023 11:15

incredible

Ответить
Nitin
Nitin - 22.07.2023 22:26

git worktree

Ответить
Hajime Kuma
Hajime Kuma - 20.07.2023 04:22

"advanced" ... yeah right

Ответить
Javier Gonzalez
Javier Gonzalez - 14.07.2023 22:14

i made my own git log with alias with the pretty=format option
something like
alias gl='git log --pretty=format:"%C(dim white)%ad%Creset %C(bold red)%h%Creset %C(bold yellow)%d%Creset %C(bold blue)%an%Creset %C(bold green)%s%Creset" '

alias gln='git log --pretty=format:"%C(dim white)%ad%Creset %C(bold red)%h%Creset %C(bold yellow)%d%Creset %C(bold blue)%an%Creset %C(bold green)%s%Creset" -p --name-only'

hope you find it usefull

Ответить
CL-78
CL-78 - 14.07.2023 16:41

I keep wondering if fireship is the same guy from neetcode. They both have the valley speech pattern.

Ответить
NineSun
NineSun - 10.07.2023 18:17

Also the dash "trick" works with cd. just "cd -" and you switch to working directory you where in on cd before. It took years to find out about that.

Ответить
Lazar Otasevic
Lazar Otasevic - 04.07.2023 21:36

nobody uses pull-requests in 2023, does it?

Ответить
NoMachine
NoMachine - 04.07.2023 03:49

long live to master branch

Ответить
null null
null null - 03.07.2023 15:05

Renaming all my branches to Masser

Ответить
James Foo
James Foo - 03.07.2023 11:27

It should be very rare to need to use "force". If you are working solo on a feature then do what you want, but when collaborating you should be pulling the remote changes often, and fixing conflicts from other dev code locally, then push up.

Ответить
Bhadri Narayanan
Bhadri Narayanan - 02.07.2023 15:20

man these videos are so funny and useful kudos to fireship

Ответить
McMurchie
McMurchie - 01.07.2023 18:38

This is too confusing, i'm just gonna delete the whole repo and clone it again.

Ответить
Jody Bruchon Tech
Jody Bruchon Tech - 01.07.2023 08:51

I always name my master branch master. "Main" is politically correct trash forced by SJWs.

Ответить
Bob Weiram
Bob Weiram - 19.06.2023 19:32

GIT is just a source control library exposed to the CLI as an API.

Ответить
k98killer
k98killer - 19.06.2023 04:42

I try to use default behavior as much as possible, so the whole "change your master branch name to main because that's so 2020 woke" thing doesn't land. I have actually experienced problems with git repositories and ci/cd tools because of this nonsense. Either change the default behavior so it just works or stop bitching about how a word offends you on behalf of some imaginary friend.

Ответить
Shahar Har-Shuv
Shahar Har-Shuv - 19.06.2023 02:04

I can't believe bisect is a thing!! I literally did it manually so many times!!! thanks!!!

Ответить
Null
Null - 14.06.2023 13:48

Jenkins is to Git hooks as angular is to JavaScript.
Just another tool to do the same crap you already can do.

Ответить
max_ishere
max_ishere - 13.06.2023 16:06

I am so confused by merging conflicts. Not because I dont understand what is what, but because git just obliterated the entire thing

Ответить
Fred Williams
Fred Williams - 12.06.2023 11:19

The most important thing that should be on everyone's mind currently should be to invest in different sources of income that doesn't depend on the government. Especially with the current economic crisis around the word. This is still a good time to invest in various stocks, Gold, silver and digital currencies.

Ответить
Alessio Sangalli
Alessio Sangalli - 10.06.2023 06:11

Nice, now I know how to rename the "main" branch to a more sensible "master"

Ответить
Fungous Lobster
Fungous Lobster - 09.06.2023 21:30

great video

I'm still confused as fuck

Ответить