{"id":63438,"date":"2022-04-06T09:00:53","date_gmt":"2022-04-06T09:00:53","guid":{"rendered":"https:\/\/www.cryptocabaret.com\/?p=63438"},"modified":"2022-04-06T09:00:53","modified_gmt":"2022-04-06T09:00:53","slug":"10-git-tips-we-cant-live-without","status":"publish","type":"post","link":"https:\/\/www.cryptocabaret.com\/?p=63438","title":{"rendered":"10 Git tips we can&#8217;t live without"},"content":{"rendered":"<p><span class=\"field field--name-title field--type-string field--label-hidden\">10 Git tips we can&#8217;t live without<\/span><br \/>\n<span class=\"field field--name-uid field--type-entity-reference field--label-hidden\"><a title=\"View user profile.\" href=\"https:\/\/opensource.com\/users\/amyjune\" class=\"username\">AmyJune Hineline<\/a><\/span><br \/>\n<span class=\"field field--name-created field--type-created field--label-hidden\">Wed, 04\/06\/2022 &#8211; 03:00<\/span><\/p>\n<div data-drupal-selector=\"rate-node-69836\" class=\"rate-widget-thumbs-up\">\n<div class=\"rate-thumbs-up-btn-up rate-thumbs-up-btn-up vote-pending\">Up<\/div>\n<div class=\"rate-score\"><a href=\"https:\/\/opensource.com\/user\/register?absolute=1\">Register<\/a> or <a href=\"https:\/\/opensource.com\/user\/login?current=\/rss.xml&amp;absolute=1\">Login<\/a> to like.<\/div>\n<\/div>\n<div class=\"clearfix text-formatted field field--name-body field--type-text-with-summary field--label-hidden field__item\">\n<p>Git tips are a dime a dozen, and it&#8217;s a good thing because you can never get enough of them. If you use Git every day, then every tip, trick, and shortcut you can find is potentially time and effort saved. I asked Opensource.com community members for their favorite Git hacks. Here they are!<\/p>\n<\/p>\n<div class=\"embedded-resource-list callout-float-right\">\n<div class=\"field field--name-title field--type-string field--label-hidden field__item\">More on Git<\/div>\n<div class=\"field field--name-links field--type-link field--label-hidden field__items\">\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/resources\/what-is-git?intcmp=7013a000002CxqLAAS\">What is Git?<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/downloads\/cheat-sheet-git?intcmp=7013a000002CxqLAAS\">Git cheat sheet<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/downloads\/cheat-sheet-markdown?intcmp=7013a000002CxqLAAS\">Markdown cheat sheet<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/tags\/git?intcmp=7013a000002CxqLAAS\">New Git articles<\/a><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<h2>add<\/h2>\n<p>The <code>git add --patch<\/code> (<code>-p<\/code> for short) command kicks off an interactive review of chunks of changes that you can add, split into smaller chunks, or ignore (among other things). That way, you can be sure to limit your changes to a specific commit.<\/p>\n<p>\u2014<a href=\"https:\/\/opensource.com\/users\/kthull\" target=\"_blank\" rel=\"noopener\">Kevin Thull<\/a><\/p>\n<p>I use <code>git add -p<\/code> to review changes a hunk at a time before they&#8217;re committed. It lets you check whether you forgot to remove some sketchy ideas, stray comments, or other things you shouldn&#8217;t commit.<\/p>\n<p>\u2014<a href=\"https:\/\/opensource.com\/users\/liberatr\" target=\"_blank\" rel=\"noopener\">Ryan Price<\/a><\/p>\n<h2>amend<\/h2>\n<p>The Git option <code>--amend<\/code> is a helpful alternative to creating several commits and then squashing them into one commit through an interactive rebase. I like that you can continually amend your first commit to add additional changes as necessary.<\/p>\n<p>\u2014<a href=\"https:\/\/opensource.com\/users\/ashleyhardin\" target=\"_blank\" rel=\"noopener\">Ashley Hardin<\/a><\/p>\n<h2>bisect<\/h2>\n<p>I know I screwed something up, but I have no idea when. That&#8217;s what <code>git-bisect<\/code> is for.<\/p>\n<p>In a previous life, I was a backend developer of Drupal and WordPress at an agency outside of Chicago. I had multiple customer sites I was working on at any one time, bouncing back and forth between them like a pinball. Every now and then, someone would find an undocumented feature in my code and, with fuzzy memory because of all the different client sites, <code>git-bisect<\/code> would come in handy with helping me find the culprit.<\/p>\n<p>\u2014<a href=\"https:\/\/twitter.com\/michalsen\" target=\"_blank\" rel=\"noopener\">Eric Michalsen<\/a><\/p>\n<h2>blame<\/h2>\n<p>Contrary to the name of the <code>git blame<\/code> command, I don&#8217;t use it to blame others. It&#8217;s great when you&#8217;re taking over repositories that you didn&#8217;t initialize. You can see when certain changes were completed and hopefully the commit messages behind them too. It&#8217;s a wonderful troubleshooting tool.<\/p>\n<p>\u2014<a href=\"https:\/\/opensource.com\/users\/miriamgoldman\">Miriam Goldman<\/a><\/p>\n<h2>checkout<\/h2>\n<p>I use <code>git checkout -<\/code> to change to the previous branch. It&#8217;s handy for switching from a feature branch back to the main development branch and back again.<\/p>\n<p>\u2014<a href=\"https:\/\/opensource.com\/users\/kthull\" target=\"_blank\" rel=\"noopener\">Kevin Thull<\/a><\/p>\n<h2>diff<\/h2>\n<p>I like the <code>git diff --staged<\/code> command to review all of the staged changes before committing.<\/p>\n<p>\u2014<a href=\"https:\/\/opensource.com\/users\/kthull\" target=\"_blank\" rel=\"noopener\">Kevin Thull<\/a><\/p>\n<h2>status<\/h2>\n<p>I seem to touch many files when I work, and <code>git status<\/code> is a lifesaver. Understanding the state of the working directory and staging area with <code>git status<\/code> has helped me learn those core concepts in Git and make sure all my work is committed!<\/p>\n<p>\u2014<a href=\"https:\/\/github.com\/ravilach\" target=\"_blank\" rel=\"noopener\">Ravi Lachhman<\/a>, Field CTO at Shipa<\/p>\n<h2>squash (rebase -i)<\/h2>\n<p>I like to use <a href=\"https:\/\/opensource.com\/article\/22\/4\/manage-git-commits-rebase-i-command\" target=\"_blank\" rel=\"noopener\">this command<\/a> to squash several commits into one. Start by using <code>git rebase -i HEAD~#<\/code> where <code>#<\/code> is the number of commits to squash. Change <code>pick<\/code> to <code>squash<\/code> on each commit that should become part of the one <em>above<\/em> it. Then edit your commit messages as you see fit. It keeps the commit history very tidy.<\/p>\n<p>\u2014<a href=\"https:\/\/opensource.com\/users\/cdrmarks\" target=\"_blank\" rel=\"noopener\">Ryan Marks<\/a><\/p>\n<h2>update-index<\/h2>\n<p>Use this with caution!<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"bash geshifilter-bash\"><span class=\"co4\">$ <\/span><span class=\"kw2\">git update-index<\/span> <span class=\"re5\">--assume-unchanged<\/span> path<span class=\"sy0\">\/<\/span>to<span class=\"sy0\">\/<\/span><span class=\"kw2\">file<\/span><\/code><\/span><\/pre>\n<p>It&#8217;s handy for marking a file unchanged that has local changes or just one of those pesky files that continually swears it&#8217;s been changed even though you&#8217;ve done absolutely nothing to it.<\/p>\n<p>\u2014<a href=\"https:\/\/opensource.com\/users\/kthull\" target=\"_blank\" rel=\"noopener\">Kevin Thull<\/a><\/p>\n<h2>worktree<\/h2>\n<p>One of my favorites is the <code>git-worktree<\/code> feature, which <a href=\"https:\/\/opensource.com\/article\/21\/4\/git-worktree\">manages simultaneous checkouts<\/a> of different branches in a repo without making a wholesale copy of the files.<\/p>\n<p>Here&#8217;s an example:<\/p>\n<pre>\n<span class=\"geshifilter\"><code class=\"bash geshifilter-bash\"><span class=\"co4\">$ <\/span><span class=\"kw2\">git<\/span> worktree add ..<span class=\"sy0\">\/<\/span>feature-branch feature-branch<\/code><\/span><\/pre>\n<p>\u2014<a href=\"https:\/\/twitter.com\/thekurtwk\" target=\"_blank\" rel=\"noopener\">KURT W.K.<\/a><\/p>\n<h2>Wrap up<\/h2>\n<p>Now it&#8217;s time to suggest your own favorite tips. What Git commands save you time, or prevent mistakes? What tips do you pass on to new Git users at your workplace? Let us know as we celebrate 17 years of Git goodness this week!<\/p>\n<\/div>\n<div class=\"clearfix text-formatted field field--name-field-article-subhead field--type-text-long field--label-hidden field__item\">\n<p>Opensource.com community members share their favorite Git tips for saving time or preventing mistakes.<\/p>\n<\/div>\n<div class=\"field field--name-field-lead-image field--type-entity-reference field--label-hidden field__item\">\n<article class=\"media media--type-image media--view-mode-caption\">\n<div class=\"field field--name-field-media-image field--type-image field--label-hidden field__item\">  <img decoding=\"async\" src=\"https:\/\/www.cryptocabaret.com\/wp-content\/uploads\/2022\/04\/wfh_work_home_laptop_work.png\" width=\"1041\" height=\"584\" alt=\"Working from home at a laptop\" title=\"Working from home at a laptop\" loading=\"lazy\"><\/div>\n<div class=\"field field--name-field-caption field--type-text-long field--label-hidden caption field__item\"><span class=\"caption__byline\">Image by: <\/span><\/p>\n<p>Opensource.com<\/p>\n<\/div>\n<\/article>\n<\/div>\n<div class=\"field field--name-field-tags field--type-entity-reference field--label-hidden field__items\">\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/tags\/git\" hreflang=\"en\">Git<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/tags\/opensourcecom-community\" hreflang=\"en\">Opensource.com community<\/a><\/div>\n<\/p><\/div>\n<div class=\"field field--name-field-listicle-title field--type-string field--label-hidden field__item\">What to read next<\/div>\n<div class=\"field field--name-field-listicles field--type-entity-reference field--label-hidden field__items\">\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/article\/22\/4\/git-aliases-bashrc\" hreflang=\"en\">What Git aliases are in your .bashrc?<\/a><\/div>\n<div class=\"field__item\"><a href=\"https:\/\/opensource.com\/article\/21\/4\/git-stash\" hreflang=\"und\">A practical guide to using the git stash command<\/a><\/div>\n<\/p><\/div>\n<div class=\"field field--name-field-default-license field--type-list-string field--label-hidden field__item\"><a rel=\"license\" href=\"http:\/\/creativecommons.org\/licenses\/by-sa\/4.0\/\"><br \/>\n        <img decoding=\"async\" alt=\"Creative Commons License\" src=\"https:\/\/www.cryptocabaret.com\/wp-content\/uploads\/2022\/04\/cc-by-sa-4-9.png\" title=\"This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.\"><\/a>This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.<\/div>\n<section class=\"field field--name-field-comments field--type-comment field--label-hidden comment-wrapper\">\n<div class=\"comments__count\">\n<div class=\"login\"><a href=\"https:\/\/opensource.com\/user\/register?absolute=1\">Register<\/a> or <a href=\"https:\/\/opensource.com\/user\/login?current=\/rss.xml&amp;absolute=1\">Login<\/a> to post a comment.<\/div>\n<\/p><\/div>\n<\/section>\n<p class=\"wpematico_credit\"><small>Powered by <a href=\"http:\/\/www.wpematico.com\" target=\"_blank\" rel=\"noopener\">WPeMatico<\/a><\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>10 Git tips we can&#8217;t live without AmyJune Hineline Wed, 04\/06\/2022 &#8211; 03:00 Up Register or Login to like. Git tips are a dime a dozen, and it&#8217;s a good thing because you can never get enough of them. If you use Git every day, then every tip, trick, and shortcut you can find is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":63439,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[307],"tags":[],"class_list":["post-63438","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-open-source"],"_links":{"self":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/posts\/63438","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=63438"}],"version-history":[{"count":0,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/posts\/63438\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=\/wp\/v2\/media\/63439"}],"wp:attachment":[{"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=63438"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=63438"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cryptocabaret.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=63438"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}