{"id":3055,"date":"2013-05-28T14:43:59","date_gmt":"2013-05-28T14:43:59","guid":{"rendered":"http:\/\/www.gubatron.com\/blog\/?p=3055"},"modified":"2016-01-02T21:40:52","modified_gmt":"2016-01-02T21:40:52","slug":"my-git-cheat-sheet","status":"publish","type":"post","link":"https:\/\/www.gubatron.com\/blog\/my-git-cheat-sheet\/","title":{"rendered":"My Git Cheat-sheet"},"content":{"rendered":"<p>I don&#8217;t know if it&#8217;s the crazy syntax, but for the life of me, I always need to come back to this cheat sheet, maybe you will too:<\/p>\n<p><strong>GIT CHEATSHEET<\/strong><\/p>\n<p><strong>fetch remote branch.<\/strong><br \/>\n<code>git fetch origin nameofbranch<\/code><br \/>\n&#8220;fetch&#8221; downloads the changes of the remote branch but doesn&#8217;t automatically merge them.<br \/>\nIf you have commited local changes on that branch, you usually fetch and then rebase your changes at the end of the fetched updates.<\/p>\n<p><strong>push local branch to remote<\/strong><br \/>\n<code>git push origin<\/code> (pushes current branch to default remote branch)<br \/>\n<code>git push origin nameofbranch<\/code> (pushes current branch to the remote <code>nameofbranch<\/code> branch)<\/p>\n<p><strong>delete remote branch (who the fuck thought of this syntax?)<\/strong><br \/>\n<code>git push origin :branchToDelete<\/code> (deletes branch on remote repo)<br \/>\n<code>git branch -D branchToDelete<\/code> (deletes branch on local repo)<\/p>\n<p><strong>clean untracked files (not folders)<\/strong><br \/>\n<code>git clean -f -x<\/code><\/p>\n<p><strong>list your remote repository aliases and full paths<\/strong><br \/>\n<code>git remote -v<\/code><\/p>\n<p><strong>How to undo the last commit but keeping the changes<\/strong><br \/>\n<code>git reset HEAD~1<\/code><\/p>\n<p><strong>How to remove the last commit from the remote<\/strong><br \/>\n<code>git reset --hard HEAD~1<\/code><br \/>\n<code>git push --force<\/code> (careful with the &#8211;force if you&#8217;re working with somebody else)<\/p>\n<p><strong>While working on a feature branch<\/strong><\/p>\n<blockquote><p>\n  &#8220;Ideally, you do git pull &#8211;rebase or git rebase upstream\/master instead of merges while working on a feature branch so that you don&#8217;t get merges.&#8221;<br \/>\n  -@laanwj\n<\/p><\/blockquote>\n<p><strong>Discard local changes and replace with what\u2019s on the remote repository for current branch.<\/strong><br \/>\n<code>git fetch origin<\/code><br \/>\n<code>git reset --hard origin\/myBranchHere<\/code><\/p>\n<p><strong>Rebase+Squash all changes of your feature branch<\/strong> (since you started that branch out of master.)<\/p>\n<p>Standing on the branch\u2026<\/p>\n<p><code>git rebase -i master<\/code> (the <code>-i<\/code> stands for interactive rebase)<\/p>\n<p>All commits will shown.<\/p>\n<p><strong>Switch to Pull Request branch<\/strong><br \/>\n<code>git fetch origin pull\/ID\/head:BRANCHNAME<br \/>\n$ git checkout BRANCHNAME<\/code><\/p>\n<p><b>Checking out a branch from someone\u2019s fork of your project to test\/fix pull request.<\/b><br \/>\nSay user \u2018alice\u2019 is submitting a pull request from a branch called \u2018wonderland-feature\u2019<br \/>\nYou want to test that branch locally, this is how you get it.<br \/>\n<code>#first add a remote for that repo.<br \/>\ngit remote add alice https:\/\/github.com\/alice\/our_project<br \/>\n#download her branch<br \/>\ngit fetch alice wonderland-feature<br \/>\n#create a local branch with her remote wonderland-feature branch<br \/>\ngit checkout -b wonderland-feature alice\/wonderland-feature<\/code><\/p>\n<p>Now <code>git log<\/code> should show the same commits as on her repo.<br \/>\nCommit to the branch if you want to fix something for alice, and then push to your<br \/>\nfork (by convention your fork is called <code>origin<\/code>) of the repo, then send her a pull request<br \/>\nfrom your fork.<br \/>\n<code># uploads the branch to your fork, from there send her pull request.<br \/>\ngit push origin wonderland-feature<\/code><\/p>\n<p>Once she has merged your changes, if you feel her branch is good now, you can now merge hell pull request on the <code>upstream<\/code> repository.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I don&#8217;t know if it&#8217;s the crazy syntax, but for the life of me, I always need to come back to this cheat sheet, maybe you will too: GIT CHEATSHEET fetch remote branch. git fetch origin nameofbranch &#8220;fetch&#8221; downloads the changes of the remote branch but doesn&#8217;t automatically merge them. If you have commited local [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3457,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[15,30],"tags":[266,484],"class_list":["post-3055","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-code","category-geeklife","tag-cheat-sheet","tag-git"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2013\/05\/Screen-Shot-2016-01-02-at-4.40.11-PM.png?fit=1395%2C809&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5Unzf-Nh","jetpack-related-posts":[{"id":3150,"url":"https:\/\/www.gubatron.com\/blog\/how-to-add-an-existing-git-repository-to-github\/","url_meta":{"origin":3055,"position":0},"title":"How to add an existing GIT repository to github.","author":"gubatron","date":"August 31, 2013","format":false,"excerpt":"Most of the times, it makes more sense to start working on something that slowly transforms into the beginning of a project that deserves to be on github. This post is about creating a local repository and putting it on github. 1. First we must convert the main local folder\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3646,"url":"https:\/\/www.gubatron.com\/blog\/git-how-to-replace-your-master-branch-with-another-branch\/","url_meta":{"origin":3055,"position":1},"title":"[GIT] How to replace the master branch with another branch.","author":"gubatron","date":"January 3, 2017","format":false,"excerpt":"TL;DR; git checkout master git reset --hard fixed-master-branch git push origin master -f Sometimes someone may pollute the 'master' branch and you may have noticed this only after you've fetched, rebased and pushed your commits. So your history may end up like this (I'll use decimal numbers on the commit\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4122,"url":"https:\/\/www.gubatron.com\/blog\/screw-configuring-gpg-to-sign-git-commits-do-it-with-your-same-ssh-key-like-this\/","url_meta":{"origin":3055,"position":2},"title":"Screw configuring GPG to sign git commits, do it with your same SSH key like this","author":"gubatron","date":"January 30, 2025","format":false,"excerpt":"GPG gives a lot of shit on macos for some reason. It's best to just add the same SSH authentication key you have on github as a \"Signing Key\" in your github account signing configuration. Go to Settings > SSH and GPG Keys You can then configure your github client\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2025\/01\/ssh_sign.jpg?fit=736%2C441&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2025\/01\/ssh_sign.jpg?fit=736%2C441&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2025\/01\/ssh_sign.jpg?fit=736%2C441&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2025\/01\/ssh_sign.jpg?fit=736%2C441&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":2087,"url":"https:\/\/www.gubatron.com\/blog\/mercurial-for-subversion-expats-merging-remote-changes-abort-push-creates-new-remote-heads\/","url_meta":{"origin":3055,"position":3},"title":"Mercurial for Subversion Expats: Merging remote changes. &#8220;abort: push creates new remote heads!&#8221;","author":"gubatron","date":"November 14, 2010","format":false,"excerpt":"Commit anywhere\/anytime with Mercurial So you have been using subversion for the past few years and now your team has decided to move on to Mercurial for all the benefits. Two or more people are working on the same branch and they're pushing code to the main copy of the\u2026","rel":"","context":"In &quot;Code&quot;","block_context":{"text":"Code","link":"https:\/\/www.gubatron.com\/blog\/category\/code\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":742,"url":"https:\/\/www.gubatron.com\/blog\/pollbet-what-version-control-system-do-you-use\/","url_meta":{"origin":3055,"position":4},"title":"[Poll\/Bet] What version control system do you use?","author":"gubatron","date":"March 19, 2008","format":false,"excerpt":"About Version Control Source: wikipedia.org Revision Control (also known as version control (system) (VCS), source control or (source) code management (SCM)) is the management of multiple revisions of the same unit of information. It is most commonly used in engineering and software development to manage ongoing development of digital documents\u2026","rel":"","context":"In &quot;Bets&quot;","block_context":{"text":"Bets","link":"https:\/\/www.gubatron.com\/blog\/category\/bets\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4178,"url":"https:\/\/www.gubatron.com\/blog\/mining-git-history-to-build-developer-agent-personas\/","url_meta":{"origin":3055,"position":5},"title":"Mining Git History to Build Developer Agent Personas","author":"gubatron","date":"February 22, 2026","format":false,"excerpt":"A new software engineering practice for the age of agentic teams and an honest look at what it costs There is a new kind of software team forming inside repositories everywhere. It is not made of humans alone. It is made of humans and AI agents working together, agents that\u2026","rel":"","context":"In &quot;AI&quot;","block_context":{"text":"AI","link":"https:\/\/www.gubatron.com\/blog\/category\/ai\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2026\/02\/download.jpeg?fit=1168%2C784&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2026\/02\/download.jpeg?fit=1168%2C784&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2026\/02\/download.jpeg?fit=1168%2C784&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2026\/02\/download.jpeg?fit=1168%2C784&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.gubatron.com\/blog\/wp-content\/uploads\/2026\/02\/download.jpeg?fit=1168%2C784&ssl=1&resize=1050%2C600 3x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/3055","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/comments?post=3055"}],"version-history":[{"count":14,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/3055\/revisions"}],"predecessor-version":[{"id":3367,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/posts\/3055\/revisions\/3367"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/media\/3457"}],"wp:attachment":[{"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/media?parent=3055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/categories?post=3055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gubatron.com\/blog\/wp-json\/wp\/v2\/tags?post=3055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}