<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Abbi Devins-Suresh</title>
    <description>The latest articles on DEV Community by Abbi Devins-Suresh (@aesther2012).</description>
    <link>https://dev.to/aesther2012</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F339048%2Fdca05b9b-bbea-4af9-a199-8b9feb9c0693.jpg</url>
      <title>DEV Community: Abbi Devins-Suresh</title>
      <link>https://dev.to/aesther2012</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aesther2012"/>
    <language>en</language>
    <item>
      <title>Tips/Tricks for a beginner to Git/GitHub</title>
      <dc:creator>Abbi Devins-Suresh</dc:creator>
      <pubDate>Sat, 04 Mar 2023 18:59:17 +0000</pubDate>
      <link>https://dev.to/aesther2012/tipstricks-for-a-beginner-to-gitgithub-3kii</link>
      <guid>https://dev.to/aesther2012/tipstricks-for-a-beginner-to-gitgithub-3kii</guid>
      <description>&lt;p&gt;When I switched from medicine to software engineering as a career path, one of the first intimidating things I had to learn was how to handle source control.&lt;/p&gt;

&lt;p&gt;The first hurdle was to understand why I needed another copy of my work in a remote location (something I quickly understood the reasoning for when I deleted something that was working and couldn’t get it working again haha because I couldn’t remember what state things were in)&lt;/p&gt;

&lt;p&gt;So below is a compilation of the commands I’ve learned in my Git journey to help me stay sane. I’m sure a bunch of these could be found online somewhere (maybe even on official documentation sites but I don’t know about you but I found them and even to this day find them very hard to approach and understand sometimes).&lt;/p&gt;

&lt;p&gt;The below situations are some of the most common scenarios I’ve run into (after the initial step of creating a repo on the GitHub website and then connecting the repo with a project I have locally):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Show &amp;amp; pull remote branches&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git branch -a OR git branch -r

git checkout -t remotes/repo/branch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Clear tracked files&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clean -d -f
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Accidentally commit and push a file&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git rebase -i [commit hash from before change]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change word pick to edit of hash related to commit&lt;br&gt;
Make changes to files&lt;br&gt;
(if the only change you need to do is to remove the file)-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git rm [path to file] -r
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you need to modify that file as well, first modify the file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add changed file
git commit --amend
git rebase --continue
git push --force
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alternatively for accidentally committing and pushing a file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git reset — soft [prior commit hash]
git reset file_name
git commit -m “new message for commit”
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NOTE: for only single commit in branch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit -a — amend 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;after fixing issue locally&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git rebase -i master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Show current branch:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git branch — show-current&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Unstage a file added:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git restore — staged [file path]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Undo last commit locally:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git reset HEAD~
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Cherry-pick:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Merge main in dashboard&lt;br&gt;
Choose sha of commit&lt;br&gt;
Switch to branch you would like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git cherry-pick -x &amp;lt;sha&amp;gt;
git push
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;confirm push worked and build is successful&lt;/p&gt;

&lt;p&gt;Please let me know if there are any mistakes or anything you would add :) I’m definitely still learning all of this even though I’ve been in the field for almost 3 years now.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
