Stop Using git add .

Поделиться
HTML-код
  • Опубликовано: 20 авг 2024
  • НаукаНаука

Комментарии • 242

  • @walterlol
    @walterlol 11 месяцев назад +33

    That's why I git add . when I finish a specific task before starting something else. This is more an unorganized approach to working on files.

  • @SXsoft99
    @SXsoft99 9 месяцев назад +93

    let's be serious when you work on a feature branch, until you merge it you will add all the things you modified in 95% of cases

    • @anass9487
      @anass9487 8 месяцев назад +5

      Yessir. Why over complicate things when we're already working on seperate branches. Include some formatting tools and something I like to do is pushing a code cleanup commit to remove any console.logs I used when debugging.

    • @harleyspeedthrust4013
      @harleyspeedthrust4013 8 месяцев назад +1

      ​@@anass9487because when someone else has to figure out why something exists, the commits you left behind will be invaluable to them if they're done carefully. its frustrating when you see a glaring wtf or question mark in the code and the commit that introduced it touched 50 files and has a two word message. and the guy who wrote it is gone or perhaps even dead

    • @PaulDeveaux
      @PaulDeveaux 8 месяцев назад +3

      In my workflow I don’t see the problem this is solving. I use “git add . “ all the time because I am working a ticket that specifies specific changes. I don’t make a bunch of changes and then have to be selective about what goes in the commit.

    • @teeesen
      @teeesen 8 месяцев назад

      It depends a lot on what you are doing. Object files, executables, output files from test runs, the zillions of files that get created by HDL synthesizers, project files. I’ve seen all manner of crap added. Proper use of .gitignore will take care of a lot of this, but a lot of people don’t seem to know how. (I’m dealing with some very junior developers.) Sure use `git add .`, if you want, but please do a `git status` first and think about whether all the changes it shows are all ones you want to commit. Personally, I use sourcetree and smartgit, which just avoids the whole issue by making it very easy to select the changes you want.

    • @richdobbs6595
      @richdobbs6595 8 месяцев назад

      I do git commit -am "Commit message" almost every time, followed by git push.

  • @lhxperimental
    @lhxperimental 9 месяцев назад +53

    I do code reviews, I always prefer clean merge requests. Many times developers will touch many files and make whitespace or formatting changes. This increases the time it takes to review and half of my time is spent in trying to figure out if something is a formatting chage or have they actually made a material change. When I commit, I always do a diff in my IDE and only push the material changes.

    • @lhxperimental
      @lhxperimental 9 месяцев назад +9

      It also pollutes the commit history. If a file has not changed materially in a commit, I don't want to see it in that commit.

    • @ontheruntonowhere
      @ontheruntonowhere 9 месяцев назад +3

      I find myself doing this a lot and yes, it is annoying. What's a better strategy to commit formatting changes?

    • @m97979
      @m97979 8 месяцев назад +5

      Maybe do a linter check for every PR?

    • @proosee
      @proosee 8 месяцев назад +1

      But if formatting was hardly readable then why not change it?

    • @maxz999
      @maxz999 8 месяцев назад +3

      You should use a standardized formatter and enforce it before code can be merged. This will filter out irrelevant formatting changes. It also makes the code base consistent which makes reviews quicker as well.

  • @daleryanaldover6545
    @daleryanaldover6545 11 месяцев назад +49

    Been a dev for almost 4 years now and this is the first time I heard about patch adding. I think this is what vscode does with their stage selected changes only feature with git which I do a lot since I discovered it. Before that I have branches and stashes and it can get messy real quick.

    • @ChaelCodes
      @ChaelCodes  10 месяцев назад +3

      I'm glad I was able to share this with you!

    • @thombruce
      @thombruce 9 месяцев назад +1

      Been a dev for 12 years and I didn't know this either. Git is the sort of thing that you learn once early on and then just never really revisit... until you need to revert a commit, of course, and then it's off to StackOverflow.
      Stashes are definitely a quick way to start making a mess of things. I still do use a stash very occasionally if I need to drop something I'm working on to make a quick patch elsewhere, though only if I know it's going to be a quick and easy patch and I'll be right back to the stashed changes.

    • @andrearaimondi882
      @andrearaimondi882 8 месяцев назад +1

      @@thombrucestashes are great if you’re very disciplined with them. I find they’re incredibly valuable when I’m checking if a build is good to go when I’m working on multiple things at once, which I very often find myself doing (not because I like that but because it is how it is)

  • @jakecurragh7831
    @jakecurragh7831 11 месяцев назад +18

    This popped up on my recommended. So helpful! I missed using Vim-Fugitive (not able to use Vim at work) because it let you stage changes in chunks, so this will be super handy!

    • @ChaelCodes
      @ChaelCodes  11 месяцев назад +6

      Thanks!! I'm glad you liked it!!
      They lock down the editor you can use at work? The horror! 😱

    • @probitj.kalita6459
      @probitj.kalita6459 10 месяцев назад

      Vim-Fugitive is probably the most useful Vim plugin to ever exist

  • @benloud8740
    @benloud8740 11 месяцев назад +62

    Probably not a good habbit to get in to. By only partially commiting your working directory, the state of the head of your branch is not something thats ever been run. You could easily get the branch in a state where it doesn't work. I prefer to test what i have then commit exactly that, so my branch is always good.

    • @sillysock45
      @sillysock45 11 месяцев назад +2

      Agreed, is this not the whole point of staging anyway?

    • @sillysock45
      @sillysock45 11 месяцев назад

      Agreed, is this not the whole point of staging anyway?

    • @pixl237
      @pixl237 11 месяцев назад

      I agree, and as a person who don't work feel very comfortable with git : I prefer knowing what I commit. I would love to know what @ChaelCodes think about that

    • @ChaelCodes
      @ChaelCodes  11 месяцев назад +18

      I almost always use CI to test if the branch is in a working state, so that's not an issue for me.
      The associated blog post has some more realistic examples of files and changes that you might want locally, but not on the branch.
      - editorconfigs
      - overridden api keys
      - lockfile updates (these should be in a separate PR)
      This example is a bit contrived to demonstrate how to use patch add. While I do have a bunch of unadded blog posts, normally I have fewer changes locally that aren't ready to merge. I'm normally only leaving whitespace, comments, and debugging statements behind.
      It's more about sorting a working state into discrete commits. For example, in this case, setting up excerpts and adding the new blog post should really have been 2 different commits, but I wanted to demonstrate adding files and patch adding chunks in one commit for the video.

    • @wlockuz4467
      @wlockuz4467 10 месяцев назад +3

      @@ChaelCodes Wouldn't relying on CI make the dev cycle very slow?

  • @blessdarah1256
    @blessdarah1256 10 месяцев назад +15

    The reason for patch is so that you can select what to commit and stash or discard the rest. Otherwise if your git ignore file is fine, then the git add . is just perfect. Don’t see a problem with that.

    • @yramagicman675
      @yramagicman675 8 месяцев назад +1

      This comment assumes good git hygiene. Patch adding is fantastic for making atomic commits when you get into a flow state and then realize 3 hours later that your changes should be 3 commits instead of 1. I find that any time I want to use a conjunction in my commit message I should have split the commit. In my personal projects, I usually don't care, but for work projects I try to.

    • @blessdarah1256
      @blessdarah1256 8 месяцев назад

      @@yramagicman675yes in this case it works just fine. A lot of the time, if you're working with your tasks already outline then in my case, I would commit after I handle a single task. Makes it simple enough to not really mix.

  • @Kagrath
    @Kagrath 11 месяцев назад +4

    Welcome back! I'll give patch adding a try in the future. My usual method is just adding files individually or directories of files I know are ready to go, do people often just shoot from the hip with "add ."? Scary!

    • @ChaelCodes
      @ChaelCodes  11 месяцев назад +1

      Yeah!! I've had to convince multiple coworkers to try patch adding. All the tutorials say 'git add .' too, so I understand why!

  • @armandoleon9901
    @armandoleon9901 8 месяцев назад

    Nice!!! Saves me time. I usually manually added all the files one by one to the stage and cross referenced with git status and removed any ones I accidentally added by doing git checkout - . This saves time!! Ty!!! 😊

  • @phanirithvij
    @phanirithvij 11 месяцев назад +7

    I think so too but for a different reason, my preference is to use a tui called lazygit which is far more efficient (it does breakdown for huge monorepos but worked 100% of time on all my repos)

  • @harleyspeedthrust4013
    @harleyspeedthrust4013 8 месяцев назад +1

    this is cool, I didn't know about this. my usual workflow when committing is to review the diff for all the changed files that i want to commit. this helps me catch extra garbage that i might have left in there, like a logging statement, some messy code i intended to clean up later, etc.

  • @Outfrost
    @Outfrost 8 месяцев назад +3

    This is a really neat explanation! Patch adding, but also patch checkout, has been incredibly useful in everything I do that's versioned.

  • @banjohead66
    @banjohead66 8 месяцев назад

    This is the first time I've seen this used. It's pretty slick! What I love most is how utterly intentional and deliberate it is -- it takes a lot of the "oh, whatever" out of the process.

  • @LordHog
    @LordHog 8 месяцев назад +1

    Interesting feature of patch adding is way too time consuming to go through all those changes as I don't ever have changes that aren't intended to be added. If want to have multi change set then create another branch or save it as a stash

  • @MrVoidfull
    @MrVoidfull 8 месяцев назад +1

    Awesome to see that there's a proper terminal way to do this. I've been doing basically this from the IDE's changes viewer, basically checking all of my changes line by line before adding and commiting. Even though I usually don't have any code which I do not wish to commit laying around, it's always good to check for useless white spaces, bad indents and forgotten console.log("entered method"); :D

  • @lidinzx
    @lidinzx 10 месяцев назад +2

    woww, never really knew some feature like this was in git, really helpful to know!! thanks

    • @ChaelCodes
      @ChaelCodes  10 месяцев назад

      Thanks! I'm glad you liked it!

  • @eof_lemongrab
    @eof_lemongrab 9 месяцев назад +3

    Sublime Merge is my preferred solution to this problem. Thanks for the video, it’s nice to brush up on the basics every once in a while

    • @ChaelCodes
      @ChaelCodes  8 месяцев назад

      Glad you appreciated it!

  • @culther0r0
    @culther0r0 8 месяцев назад +2

    While I personally would never have edits in a branch that I didn't intend be included with that branch getting merged this was informative at least about the feature - if I had stuff that I had to go back and forth on I heavily use branches. Perhaps before doing a pull request I may squash and review everything this way

  • @ariss3304
    @ariss3304 10 месяцев назад +4

    I think there are easier solutions than this. Files that are not ready to be committed/wip should be in a separate branch. Juggling multiple states like this can be a major security concern and all around headache.
    It feels like a gimmick to bandaid deeper problems with the working state

    • @maritzaesparza1440
      @maritzaesparza1440 10 месяцев назад +2

      But what I saw is that this is an example of how to use the command, in the real world is useful when you implement a lot of things but at the end want to have them in separate commits, every commit focus on an isolated feature and this helps you with that, I use this all the time with the magit tool in Emacs

    • @ChaelCodes
      @ChaelCodes  10 месяцев назад

      Yes, exactly! Thank you!

    • @maxz999
      @maxz999 8 месяцев назад

      This is usually what I use it for. By breaking large commits up, it makes reverting much easier and the history is more meaningful.

  • @ChrisCarlos64
    @ChrisCarlos64 10 месяцев назад +2

    I don't think I ever knew the "name" of this type of adding. I might have been on the docs, but I rarely read the docs for how to add. I use this not as much, partly because 1. I don't really find myself adding things that aren't ready to commit or 2. If I am committing to make a checkpoint, even if broken, I do it on a personal branch. I don't usually encounter problems of someone taking a branch and merging my in-development branch, so if they do, that's on them I feel. Overall though this was a lovely tutorial, great work. I usually use the GUI setup on Visual Studio when I need to do this though I mainly use the command line for everything else. Maybe I should use the CLI for this too, but again it's not something I do very commonly.

  • @checkerist
    @checkerist 8 месяцев назад

    I do the same thing with JetBrains IDE. Happy to know that there is a Git-native way for everybody!

  • @ryandsouza2962
    @ryandsouza2962 11 месяцев назад +3

    Great video! This should be in most Git tutorials :)

    • @ChaelCodes
      @ChaelCodes  11 месяцев назад

      Thanks!! That's part of why I made it. I see a lot of tutorials (not necessarily for git) that tell people to use git add . and I find myself helping coworkers unlearn this, because they end up with unwanted changes in their commits, and then we have to rebase or amend to fix it. I think being intentional about what goes into the commit really helps people avoid a lot of those issues.

    • @ChaelCodes
      @ChaelCodes  11 месяцев назад

      I'm thinking about following it up with one on interactive rebasing, and some of my favorite flags, but I'm not sure yet.

    • @ryandsouza2962
      @ryandsouza2962 11 месяцев назад +1

      That would be amazing! Rebase is something that I still need understanding on :)

    • @davidmartensson273
      @davidmartensson273 10 месяцев назад

      @@ryandsouza2962 Rebase means taking all your local commits and replaying them on top of some other branch or history so that all your changes is in the end of that commit history. I you did a merge instead, your commits would be interspaced between other commits based on time, and that could force you to resolve merge conflicts multiple times for the same code.
      Rebasing adds all of your in order on the same source so the only time you would need to resolve multiple merge conflicts is between your changes.
      Also, in case you go back to this later, all you changes will be in one sequence making it easier to follow, and on case you have a branch living for a longer time (you probably should not, but...) you will usually have an easier time to show of your changes in a PR.

  • @mika2666
    @mika2666 11 месяцев назад +21

    I really like the terminal but selecting what goes into my commits is a GUI task for me, both vsc and intellij have git UIs that help me more than the terminal ever could. Maybe I'll switch some day, bookmarked this video for that day.

    • @ChaelCodes
      @ChaelCodes  11 месяцев назад +16

      I like the control and the consistency. I've swapped between a few editors and OS's and the CLI is the same always. I also like that the CLI "just works" if I'm pair programming in someone else's dev setup.
      Spending time learning how to use the CLI is an investment I don't regret, but if you've got a system that works for you, more power to you!

    • @Andrew90046zero
      @Andrew90046zero 10 месяцев назад +1

      I was thinking a similar thing. Ultimately, I see the ideal situation being using a GUI for the repetitive trivial stuff, and then the command line exists for when you need to do somthing specific that you might not do that often.

    • @vikingthedude
      @vikingthedude 9 месяцев назад +1

      Two words: sublime merge

    • @matthewcullum7551
      @matthewcullum7551 9 месяцев назад

      @ChaelCodes Knowing how to commit hunks rather than whole files on the command line is an invaluable skill to have for exactly the reasons you mention. With that said, for general day to day work I'll still take Intellij's side by side Git diff UI any day of the week! It's just so clean compared to anything I've seen in CLI world. And this is coming from someone who uses the command line religiously for things like Neovim, Lazygit, and Tmux

    • @imqqmi
      @imqqmi 8 месяцев назад

      I agree. In my case I use sourcetree, so it's not depending on a specific ide or editor. I like how I can see the code with syntax highlighting, allowing me to exclude chunks of code (ie white space changes) etc. I do use git cli occasionally for collecting stats for reports, correcting corrupted git repos and line endings for example.

  • @dzisonline
    @dzisonline 8 месяцев назад +1

    Never heard of -p. Nice one!

  • @breakablec
    @breakablec 10 месяцев назад +16

    That might not be the best habit as you should test the code as you are committing it. If you are adding patches the you are obviously not doing it. I would say stashing any changes you don't want to be committed might be a better idea. You can use the technique in the video to help you do that.

    • @davidmartensson273
      @davidmartensson273 10 месяцев назад +2

      I agree. Adding individual files might work for small projects, but for bigger projects keeping track on which files contain changes you want and making sure a file does not contain changes linked to other files you do not commit will very quickly become a serious problem, I use feature branches for separation always.
      Sure, if I do a minimal change of a single or just 2-3 files and I know I have not touched them for any other purpose I do sometimes commit just those, but in most cases I would still branch and then in the branch remove any other change.
      The reason is that I can then push that branch to the shared repo and have others check it out easily instead of having them picking just a commit, as picking the commit only could end up creating conflicting identical commits.
      This is of cause not a problem for a single dev, and for a small blog, sure, but as a general advice, no, definitely no :)

  • @Redyf
    @Redyf 8 месяцев назад

    I can't believe I had no idea about that command. Thanks for sharing Chael

  • @davidbuchan2909
    @davidbuchan2909 8 месяцев назад

    I tend to do a git diff and go through all the changes making notes that will become the commit message. Any changes I don't want in the commit I'll manually tidy up. But again, cheers for that I'll certainly add that to my toolbox.

  • @stanleyparks
    @stanleyparks 9 месяцев назад +1

    Recently worked with people who would git add . without even checking git status to see what they had changed. Was infuriating.

    • @ChaelCodes
      @ChaelCodes  9 месяцев назад

      Cleaning up the commits afterwards is harder too! Those changes will still run into merge conflicts on a rebase, even though they weren't needed.

  • @pedromenezes4013
    @pedromenezes4013 10 месяцев назад +2

    Great tip and really easy to understand explanation! Thanks!

  • @bristol-emo
    @bristol-emo 11 месяцев назад +2

    I use `git add -p :/` all the time. You can add changes selectively for all files from any directory in the repository.

    • @ChaelCodes
      @ChaelCodes  11 месяцев назад +1

      Including untracked ones? I've been trying to find a way to do that for a while. I'll have to try this out!

  • @Marfig
    @Marfig 9 месяцев назад +2

    I'll keep using git add . But thanks for the advise.

  • @dipteshchoudhuri
    @dipteshchoudhuri 9 месяцев назад +1

    I suggest something like gitui (or lazygit) to make these things easier. Using CLI for patch adding is not very intuitive IMO. TUI applications make it easy.

  • @deanwilsondev
    @deanwilsondev 10 месяцев назад +1

    Cool trick, gonna give this a go next time i need it. It doesn’t necessarily replace ‘git add .’ But there are definitely cases where i would use one over the other. Thanks for sharing

    • @ChaelCodes
      @ChaelCodes  10 месяцев назад

      Thanks! I'm glad you like it!

  • @romankyrnis9461
    @romankyrnis9461 9 месяцев назад +1

    Great! Nice tip, thank you! Waiting for a lot more

  • @rajat0610
    @rajat0610 10 месяцев назад +1

    this is interesting!
    i always wondered if something like this existed, but never searched
    thanks for making the video!

    • @ChaelCodes
      @ChaelCodes  10 месяцев назад +1

      Thanks for the comment! I'm glad you iked it!

  • @drdca8263
    @drdca8263 10 месяцев назад +1

    Huh, my usual approach is to look at git diff for each of the files I’m considering adding, and if it looks good, adding the whole thing,
    and if not, I might use got add --patch on that file,
    and then finally I do commit -m ,
    I didn’t know you could do the patching in the commit step rather than in the add step. Huh!

    • @ChaelCodes
      @ChaelCodes  10 месяцев назад +1

      Glad I could show you an easier way! Try it out and let me know if you like it?

  • @ChrisShawUK
    @ChrisShawUK 9 месяцев назад +1

    Very cool ... Nice tool for certain use cases

  • @leedanilek5191
    @leedanilek5191 8 месяцев назад

    I don't see why i would have edits that i don't want to include in a pull request. The only reason to avoid git add . is it can be slow on large repos

  • @dingokidneys
    @dingokidneys 10 месяцев назад +1

    Nice neat coverage of a very useful feature. Thanks for that.

    • @ChaelCodes
      @ChaelCodes  10 месяцев назад

      Thank you!! I appreciate that!

  • @GDScriptDude
    @GDScriptDude 10 месяцев назад +1

    I'm usually using git status when I am setting up a project to tweak the .gitignore file before using git add . But, this -p is new to me, so interesting.

    • @ChaelCodes
      @ChaelCodes  10 месяцев назад +2

      Glad I was able to show you something new!

  • @vjzb3
    @vjzb3 8 месяцев назад

    I always use “git diff” to inspect my changes before adding

  • @JMIK1991
    @JMIK1991 8 месяцев назад

    I rather use git add than git -p, but I can see using pagination at times if I happen to do two things at same time in same file.
    I've been editing the file before pushing commit if git diff shows up something weird by removing the file from commit and fixing it.
    Makes commit more straight forward as by having long command will mix it up...
    For me it's better to update commit message than commit changes at once.
    Really like you made a video about this feature.
    I wonder if it works with files already added to commit list... Works.
    Or with paths... Works using 'git add -p'.

  • @cheebadigga4092
    @cheebadigga4092 11 месяцев назад +3

    Been using patch adding basically since I started using Git. I never understood why you would just add everything (except if you do a WIP commit to push or if you actually, really, really, really need everything, which mostly happens at initial commit).

    • @ChaelCodes
      @ChaelCodes  11 месяцев назад +1

      I think a lot of people don't know about their options. git's documentation is a bit thick, and a LOT of tutorials use `git add .`. It took me a lot longer to discover patch adding, but I remember falling in love instantly! 😂

    • @SahilP2648
      @SahilP2648 10 месяцев назад

      Because there is no need to lol. Don't you think it would be far more popular if this was necessary? I use "git commit -am "message"" instead of "git add -A" (git add . is deprecated afaik). "git commit -am """ doesn't add new files but it's apparent if you have missed a file by doing "git status". As to why this patch stuff is not necessary, you can always use a combination of squashing, stashing, cherry picking and merging/rebasing to get what you want. I only do half of the stuff in the terminal (mostly the two commands I mentioned before, git push -f, git rebase, git checkout, git checkout -b, git stash, git reset and git reset --hard), for the rest I use VScode and gitlens/gitless. What I have set up is far superior in terms of productivity than anything else I have seen.

    • @cheebadigga4092
      @cheebadigga4092 10 месяцев назад

      "not necessary" and "your own opinion" are not the same thing. Adding everything can be useful, but the risk of adding code you don't want in a commit is there.
      Also git add . is not deprecated. Used it yesterday just fine for my initial commits.

    • @cheebadigga4092
      @cheebadigga4092 10 месяцев назад

      Also you ARE patch adding if you're using vs code extensions to manage patches. Terminal vs. GUI is irrelevant to the discussion, that's personal preference only. Some people are productive using a GUI tool, and others are productive using terminal tools. Both essentially do the same thing. As I said, what you're pointing out is just a different way of patch adding.

    • @SahilP2648
      @SahilP2648 10 месяцев назад

      @@cheebadigga4092 VSCode is all you need lol. I use some terminal commands just because it's more productive that way. You never need this patch adding thing. Either stash your changes, discard, or commit.

  • @jewpcabra666
    @jewpcabra666 8 месяцев назад

    love that this got recommended for me - always appreciate more tips/tricks for git. You mentioned in the video that the change made for the white space would only be in the commit and not locally. Is there a way to make that edit in both places simultaenously from that view or execution stage? I wouldn't want to be out of sync

  • @davidmasaka6547
    @davidmasaka6547 10 месяцев назад +1

    This is really helpful I kept using the built in tools on vscode but I think this will be even easier and will work well for when I use vim

    • @ChaelCodes
      @ChaelCodes  10 месяцев назад +1

      Thank you!! I'm glad you like it! Feedback like this is why I make videos!

  • @skillfulactor09
    @skillfulactor09 9 месяцев назад +1

    What tech stack are you using when you create your blog?

    • @ChaelCodes
      @ChaelCodes  8 месяцев назад

      I have a Jekyll site on GitHub Pages!
      I use a GH action to deploy it, instead of the gh-pages gem, because I have several custom gems (including my own, Jekyll-Twitch). But GitHub updated to add a new GitHub action around releases, and I need to update to that.
      Here's the PR for this blog post/video - github.com/ChaelCodes/chaelcodes.github.io/pull/87

  • @hypario
    @hypario 8 месяцев назад

    let's be serious here, most people either work on a feature branch and needs to add ALL the things (and filter out what's not need) to their commit
    or they use an IDE, and by the same occasion, use git on the IDE, and are able to filter what file they wanna add to their commit
    nobody actually needs to use any of those features and would be for very niche cases...
    (aka, wanna commit only one part of a file, which is really neat and actually taught me something)

  • @andsribeiro
    @andsribeiro 8 месяцев назад

    As a jr dev, I haven't completely understood what you meant in this video but it seems really interesting and I had never heard about it before. Thank you for this.

  • @samuelgadiel
    @samuelgadiel 8 месяцев назад

    I gotta say, I found it very difficult to understand the amount of information that is showed on the screen when doing the patch adding.
    Just by watching the video I got lost trying to understand which part of the code you were adding.
    In my case, I prefer to use some program to better visualize what I'm adding to the commit.
    I use Github Desktop, it shows the diff between the files and I can select the parts that I want to add by clicking on the lines.
    It does the same thing underneath, but I found it easier to understand what I'm doing haha.

  • @bilalahmedkhan5876
    @bilalahmedkhan5876 10 месяцев назад +1

    Whoa this was really helpful, thanks for sharing!

    • @ChaelCodes
      @ChaelCodes  10 месяцев назад

      Thank you!! I appreciate it.

  • @davidbuchan2909
    @davidbuchan2909 8 месяцев назад

    not sure I'll give up git add . completely. But this is a really useful tool have have in my tool belt. Thanks

  • @TheHanutaXD
    @TheHanutaXD 9 месяцев назад

    For any one interested. The . is not a special git case. The . always refrences the current directory. Same as .. refrencing the parent directory.
    That is also why ls -a always shows those to "directories"/

  • @rickyisajedi
    @rickyisajedi 8 месяцев назад

    Great video! Learned something cool!!!

  • @bobruddy
    @bobruddy 8 месяцев назад

    thanks for the video. this will come in handy

  • @po6577
    @po6577 8 месяцев назад

    Skipping individual file or code for commit after I tests? Only work for small project really. Spend more time on branch control.

  • @domingotrejo4554
    @domingotrejo4554 10 месяцев назад

    Why i stop using this command if are very usefull, personally check every change in the tab of changes in vscode and add before this revision

  • @sloppydoggy9257
    @sloppydoggy9257 8 месяцев назад

    My most common is "git commit -a", after that I use "git add

  • @jhwheeler7
    @jhwheeler7 8 месяцев назад

    I used to use this and totally forgot about it! Thanks for the reminder. Although I will say that `git add .` is still quite useful in most cases for me, because I try to commit as often as possible in an atomic fashion.

  • @bstar777777
    @bstar777777 9 месяцев назад +3

    I'm sure other have said this, but changes should ideally be in feature branches. This process is ok in a bind, but I would never use it as a general workflow. It's just too prone to error.

    • @ChaelCodes
      @ChaelCodes  8 месяцев назад

      Feature branch here was cc-video-test. :)

  • @davisstanko
    @davisstanko 11 месяцев назад +1

    Super helpful!

    • @ChaelCodes
      @ChaelCodes  11 месяцев назад

      Thanks!! I'm glad you liked it!

  •  9 месяцев назад

    If you want to do that from a light gui terminal based tool there is gitui that does an awesome job !

  • @fearmear
    @fearmear 8 месяцев назад

    What if I have lots of new/changed files?

  • @rogo7330
    @rogo7330 8 месяцев назад

    I use `git diff` to see what still not added to the stage and `git diff ^HEAD` to see what's in stage but not commited yet.

  • @frustratedalien666
    @frustratedalien666 9 месяцев назад +2

    This maybe a dumb question, but how do you know which changes worked and which ones didn't if they are all in your working directory? The way I work, and the way I've seen others work, is that I'll be solving a problem or trying to get a test case to pass and when that works, everything that's not ignored through .gitignore are things I want to add/commit, or else my CI pipeline will fail. At the moment that my tests passed locally, I want all of those changes to be committed, if that makes sense. If I pick and choose this way, there's a good chance my CI pipeline will fail when I push and I won't know about it for at least 20 minutes 😅
    git add . can still cause problems, so I am not advocating for that and I can understand where git add -p might be useful, but I don't get git commit -p
    It probably doesn't fit my workflow because I like to squash my commits into one at the end of the day and that interactive rebase is where I handle fixing (or squashing) commit messages and stuff like that.

    • @ChaelCodes
      @ChaelCodes  9 месяцев назад +1

      Most of the changes I skip are whitespace, comments, or dev environment changes. Sometimes I'll skip a refactored method or file, because it turned out not to be necessary.
      I focused more on the how and why in the blog post - www.chael.codes/2023/09/09/stop-git-add-dot.html
      These examples are in there.

  • @shady4tv
    @shady4tv 8 месяцев назад

    ayyy super useful tip! less resets from stupid commits now lol

  • @laersonhammes2608
    @laersonhammes2608 10 месяцев назад

    Wow, i follow u on twitch and now / today, i find ur yt chanel, amaizing

  • @DisabledCookie
    @DisabledCookie 10 месяцев назад +1

    i will need to revisit this video

  • @SharunKumar
    @SharunKumar 11 месяцев назад +2

    Or, if you like your GUIs just use something like sublime merge

    • @ChaelCodes
      @ChaelCodes  11 месяцев назад

      Definitely not knocking GUIs here. If you're happy with your GUI, keep at it!

  • @flow5718
    @flow5718 10 месяцев назад +1

    As a new Git user I was spoiled by Github Desktop, can't ever see myself doing this in a terminal where I could potentially mess things up. Very low chance of that happening from a well thought out GUI like GD.

    • @simonkaran
      @simonkaran 9 месяцев назад +1

      Yes, I also think that using a GUI is less error prone

    • @peteryates308
      @peteryates308 8 месяцев назад +1

      You can have the best of both worlds by using tig, a command line git client. You can easily stage/unstage hunks with u and individual lines with 1.

  • @immer5680
    @immer5680 8 месяцев назад

    I learned something new, thank you

  • @ViktorKrejcir
    @ViktorKrejcir 8 месяцев назад

    Cool trick, however keep in mind, that this ignores binary file changes.

  • @nikhils7583
    @nikhils7583 11 месяцев назад +1

    gone through other videos also good content and passion of working on open source software , subscribed

    • @ChaelCodes
      @ChaelCodes  11 месяцев назад +1

      Thanks!! I'm glad you liked the other videos I've done too! I'm working on becoming more active.

    • @nikhils7583
      @nikhils7583 11 месяцев назад +1

      Glad to hear that

  • @qubi
    @qubi 11 месяцев назад +1

    at this point i think the best way is still source control tab.. with gitlens obv.

    • @ChaelCodes
      @ChaelCodes  11 месяцев назад +1

      I'm not knocking GUIs, if you're happy with your tools, go for it!

    • @qubi
      @qubi 11 месяцев назад +1

      @@ChaelCodes totally respect that, i like using terminal for many things too, however for this i found that seing it in gui is better for me and lets me move things faster

  • @hashisgod
    @hashisgod 8 месяцев назад

    Feels like people obsess over using git CLI, I just use my IDE plugin for git and have no problems

  • @rsjrx
    @rsjrx 10 месяцев назад

    This is added complexity and bs most people don’t need but boot camp graduates care about to signal they finally learned git

  • @abdullahX001
    @abdullahX001 11 месяцев назад +1

    awesome thank you!

    • @ChaelCodes
      @ChaelCodes  11 месяцев назад

      Thank you for watching! I'm glad you enjoyed it!

  • @CreamusG
    @CreamusG 8 месяцев назад

    Oh, git add .
    I thought you were gonna tell me to stop using git add. The latter might be a problem :)

  • @joshua_lee732
    @joshua_lee732 11 месяцев назад +1

    VS-Code for a WSL shell with vim to manage git via CLI seems like such a janky solution to me.

    • @ChaelCodes
      @ChaelCodes  11 месяцев назад +1

      I do open-source and programming games streams on Twitch, so I need Windows for the recording software and games, but I work with Ruby so a linux dev environment is preferable. VS Code with WSL is a great way to manage that.
      I have vim bindings turned on in VS Code, because I like to play with them. The editor I'm using for git is still VS Code.
      I like managing git via the CLI. I have a lot more control, and I don't have to learn a new GUI when I swap editors or OS's. Plus, it just works when I'm pairing with someone. I don't have to learn their git GUI tool.
      It may seem janky to you, but it works great for my use case.

  • @ForeverZer0
    @ForeverZer0 11 месяцев назад +2

    While this is obviously better than blindly doing "git add .", doing patch commits has its own pitfalls that one needs to be mindful of.

    • @ChaelCodes
      @ChaelCodes  11 месяцев назад

      Could you elaborate?

    • @ForeverZer0
      @ForeverZer0 11 месяцев назад +2

      @@ChaelCodes It is easier to get your HEAD out-of-sync of your working branch with partial commits. It makes accidents of one type more difficult, but easier for accidents of another kind. You moves the problem-space from "do not commit unnecessary things" to "MUST commit all necessary/related things".
      Patched commits are useful when you make the mistake of not committing often enough. If you find yourself using patched commits to "organize" them better, then this indicative of not making enough commits. It may alleviate the problem, but the real solution is to make commits of all tracked files more often.

    • @davida1d2
      @davida1d2 10 месяцев назад

      ​@@ChaelCodes I also find it dangerous and error-prone to manually add every dependency. It will break things, a human can never do such a task consistently.
      And keep it up. The video format is really good, has a nice pace to it.

  • @mariusxd4161
    @mariusxd4161 8 месяцев назад

    JetBrains IDEs have these commands as a UI feature by default lol.

  • @hosseines276
    @hosseines276 11 месяцев назад +1

    What is the colorscheme's name?

  • @forevernoob97
    @forevernoob97 8 месяцев назад

    Noice. Really useful tutorial.

  • @CottidaeSEA
    @CottidaeSEA 10 месяцев назад +1

    Good video, but I think "stop using git add ." is a bit of a clickbaity title, because that's not really the point of the video. The point is to only commit the changes you want to commit and to understand that there are ways to not commit everything at once. If git add . is appropriate for the situation, that's what you use.
    Besides, I'm far more in favor of "do many but small commits" instead of large commits. This one was honestly fairly big if you consider that you added and modified files in the same commit. In the case where you need to revert a change, it's pretty much always nicer to be able to revert a specific commit than manually editing. In many cases you still have to do manual edits though.

  • @sujanbasnet7868
    @sujanbasnet7868 11 месяцев назад +1

    awesome

    • @ChaelCodes
      @ChaelCodes  11 месяцев назад

      Thanks!! I'm glad you liked it!

  • @GillesLouisReneDeleuze
    @GillesLouisReneDeleuze 8 месяцев назад

    git add . && git commit -m "changes" && git push --force

  • @isaacreyes7563
    @isaacreyes7563 9 месяцев назад

    Git add . is fine. Oh, no. My computer crashed but I used patch add only to add the finished files and all of the other stuff I have been working on is gone. Just put everything on the hub and update as you go. patch is an unnecessary waste of time.

  • @devopstoolbox
    @devopstoolbox 9 месяцев назад +1

    Yes! One of the more important tips I only got ~4 years after working with git...
    Also, if you're working with Vim / Neovim (other IDEs as well but this is mine) then you can run a couple of integrations to make this visual and accessible - ruclips.net/video/IyBAuDPzdFY/видео.html

    • @ChaelCodes
      @ChaelCodes  9 месяцев назад +1

      I'm glad you like it!

  • @stevenrodriguez2882
    @stevenrodriguez2882 8 месяцев назад

    I feel like this would be great if you are in the middle of a task but you have finished part of the code that someone needs. Also this is my first time ever seeing patch in seven years 👀

  • @robinmordasiewicz
    @robinmordasiewicz 8 месяцев назад

    very good presenter, good tips.

  • @derciojds
    @derciojds 10 месяцев назад +1

    Hi, which vs code theme are you using?

    • @ChaelCodes
      @ChaelCodes  10 месяцев назад +1

      Horizon theme. It's beautiful!

    • @derciojds
      @derciojds 10 месяцев назад +1

      @@ChaelCodes thank you

  • @ChristianPiechotta
    @ChristianPiechotta 9 месяцев назад +3

    Great command option when in server environment. On Desktop i usually prefer git gui which comes with git full bundle and offers same features. But sure if you just use basic git package rha doesnt ship git gui you've to use the command line equivalent. 😊

    • @ChaelCodes
      @ChaelCodes  8 месяцев назад

      That's a great point! When do you use git on the server though? Specifically to make commits?

    • @ChristianPiechotta
      @ChristianPiechotta 8 месяцев назад +1

      @@ChaelCodes Currently I dont use git on server, but in the past like almost 15years ago, when git was new. Use case was if you deployed code on server i did that with git hooks. Also if code wasnt running well I used to do a Hot-Fix on server and commit/push it afterwards. But with container management tools like docker there was less & less times for doing such stuff on server. But maybe someone that uses a server instead of containers on local machine might still find himself in a situation where he appreciate cli, because of missing a gui.

    • @ChaelCodes
      @ChaelCodes  8 месяцев назад

      @@ChristianPiechotta thanks for explaining!

  • @moro3ify
    @moro3ify 8 месяцев назад

    Ok this may actually be useful but I don’t people who use vscode, and I don’t trust even more to people who commit binaries and pictures and other non-text stuff to git.

  • @connorrobinson9268
    @connorrobinson9268 8 месяцев назад

    I would just do smaller changes with smaller PRs. Easier to review. Most of my changes are smaller so I never see a need for git patch.

  • @RatchetXJ0461
    @RatchetXJ0461 11 месяцев назад

    Or you can stages chunks of files and commit them instead of doing that patches things. I do not get what this patches thing is bring on the table.

    • @ChaelCodes
      @ChaelCodes  11 месяцев назад

      Do you have some more info or documentation on this?
      Are you talking about in a GUI or using the CLI?

    • @RatchetXJ0461
      @RatchetXJ0461 11 месяцев назад

      @@ChaelCodes Hi I'm doing it in the CLI with Lazygit tool. But this is available in VS Code as well as in JetBrains solutions (I used those two git GUI before moving to full CLI and ultimately Lazygit which is a GUI but in terminal).

    • @RatchetXJ0461
      @RatchetXJ0461 11 месяцев назад +1

      @@ChaelCodes So, I've doing some google search. As we all know a GUI doesn't do much more than write cmd for us. So my GUI doing partial stage must be bound to a git add option.
      It turns out that it is --patch! So I guess there isn't much differences between doing the -p at the commit or at the staging. Except that I find it more logical or convenient to stage chunk then do a commit than adding a bunch of file and then partially committing them
      This explains why I didnt know what this option bring on the table. Simply because that's more or less what I'm already doing. The more you know...

  • @ivandimitrov4410
    @ivandimitrov4410 9 месяцев назад +1

    It's useful for some people since this functionality exists, but I can't see myself using this. I get confused easily so I try to keep commands to a minimum and generalize. git add . is the most general approach so it works fine for me.

  • @oafhauohguoihgakds5151
    @oafhauohguoihgakds5151 8 месяцев назад

    git commit -am "tl:dw"

  • @elitecoldsteel
    @elitecoldsteel 8 месяцев назад

    yeah I should probably read the man pages for the commands I use all the time hahaha

  • @Igor-ls1qq
    @Igor-ls1qq 10 месяцев назад +1

    No

  • @geraldisutanto9511
    @geraldisutanto9511 10 месяцев назад +1

    trust me use a gui folks

  • @kmfco
    @kmfco 8 месяцев назад

    so useful