<?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: Glitchbyte</title>
    <description>The latest articles on DEV Community by Glitchbyte (@glitchbyte).</description>
    <link>https://dev.to/glitchbyte</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%2F148532%2F6d4ff785-0967-47dc-88f4-e814eb533d9e.png</url>
      <title>DEV Community: Glitchbyte</title>
      <link>https://dev.to/glitchbyte</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/glitchbyte"/>
    <language>en</language>
    <item>
      <title>Rust wont save us, but it's ideas will</title>
      <dc:creator>Glitchbyte</dc:creator>
      <pubDate>Thu, 08 Feb 2024 01:58:03 +0000</pubDate>
      <link>https://dev.to/glitchbyte/rust-wont-save-us-but-its-ideas-will-3f5p</link>
      <guid>https://dev.to/glitchbyte/rust-wont-save-us-but-its-ideas-will-3f5p</guid>
      <description>&lt;h2&gt;
  
  
  What are we saving?
&lt;/h2&gt;

&lt;p&gt;Recently, I came across this article titled "&lt;a href="https://www.horizon3.ai/analysis-of-2023s-known-exploited-vulnerabilities/"&gt;Rust Won’t Save Us: An Analysis of 2023’s Known Exploited Vulnerabilities&lt;/a&gt;".&lt;/p&gt;

&lt;p&gt;Being the clickbait it is, I clicked.&lt;/p&gt;

&lt;p&gt;Quick background on me: I've worked in cybersecurity for almost 10 years. I know cybersecurity way more than I know development.&lt;/p&gt;

&lt;p&gt;My day job is securing infrastructure and code. &lt;/p&gt;

&lt;p&gt;An article like this piques my interest. &lt;/p&gt;

&lt;p&gt;I've been writing programs in Rust for a few years now.&lt;/p&gt;

&lt;p&gt;I started writing Rust because of its claim to memory safety, and it became my favorite language to use. I've even managed to ship Rust to prod in one of the coolest projects I've had the honor of being apart of.&lt;/p&gt;

&lt;p&gt;So what is this article talking about?&lt;/p&gt;

&lt;p&gt;TL;DR: Rust was made to solve memory-related vulnerabilities and issues, but that only makes up 19.5% of the most exploited vulnerabilities in 2023. Routing and Path abuse exploits tied for second place with memory vulns, followed by Default Secrets (4.9%), Request Smuggling(4.9%), and Weak Encryption (2.4%). The most abused exploit? Insecure Exposed Functions (IEF), at 48.8%.&lt;/p&gt;

&lt;p&gt;The article goes onto making the most generic recommendations any cybersec professional would know:&lt;/p&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;Vendors

&lt;ol&gt;
&lt;li&gt;Develop the depth of knowledge of your engineers in the frameworks they use&lt;/li&gt;
&lt;li&gt;Harden, standardize, and audit the use of those frameworks across products&lt;/li&gt;
&lt;li&gt;Enable and expose verbose logging for your products&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;Developers

&lt;ol&gt;
&lt;li&gt;Assume all code you write is reachable from an unauthenticated context&lt;/li&gt;
&lt;li&gt;Practice defense-in-depth programming and don’t make it easy for an attacker to shell out&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;Defenders

&lt;ol&gt;
&lt;li&gt;Reduce any attack surface exposed to the internet if its not needed there&lt;/li&gt;
&lt;li&gt;Proactively enable logging, and remote logging if possible, for all products that touch the internet&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;Researchers

&lt;ol&gt;
&lt;li&gt;Look for bugs in the places frameworks come together&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;Therefore, Rust won't save us.&lt;/p&gt;

&lt;p&gt;There is some truth to that, and the advice given by the article is also correct.&lt;/p&gt;

&lt;p&gt;But it doesn't dig into why Rust was made in the first place.&lt;/p&gt;

&lt;p&gt;It doesn't ask the question "Can we reduce/eliminate IEF abuse similar to how we reduced memory vulnerabilities?"&lt;/p&gt;

&lt;h2&gt;
  
  
  Looking at IEF
&lt;/h2&gt;

&lt;p&gt;What are Insecure Exposed Functions, exactly?&lt;/p&gt;

&lt;p&gt;Lets take a look at the &lt;a href="https://cwe.mitre.org/data/definitions/749.html"&gt;MITRE&lt;/a&gt; definition:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The product provides an Applications Programming Interface (API) or similar interface for interaction with external actors, but the interface includes a dangerous method or function that is not properly restricted. &lt;/p&gt;

&lt;p&gt;This weakness can lead to a wide variety of resultant weaknesses, depending on the behavior of the exposed method. It can apply to any number of technologies and approaches, such as ActiveX controls, Java functions, IOCTLs, and so on.&lt;/p&gt;

&lt;p&gt;The exposure can occur in a few different ways&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The function/method was never intended to be exposed to outside actors.&lt;/li&gt;
&lt;li&gt;The function/method was only intended to be accessible to a limited set of actors, such as Internet-based access from a single web site.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;IEF is access to functions the outside world should never have had access to in the first place.&lt;/p&gt;

&lt;p&gt;Lets look at an example from the same page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;removeDatabase&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;databaseName&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Statement&lt;/span&gt; &lt;span class="n"&gt;stmt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;createStatement&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="n"&gt;stmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;execute&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"DROP DATABASE "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;databaseName&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;SQLException&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="o"&gt;...&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we have a Java method &lt;code&gt;removeDatabase&lt;/code&gt; that will delete a database with the name specified in the parameter. &lt;/p&gt;

&lt;p&gt;The problem is this method should never have been public. By declaring it public, the rest of the application has access to this method, even though it should be restricted.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;removeDatabase&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;databaseName&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Statement&lt;/span&gt; &lt;span class="n"&gt;stmt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;createStatement&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="n"&gt;stmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;execute&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"DROP DATABASE "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;databaseName&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;SQLException&lt;/span&gt; &lt;span class="n"&gt;ex&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="o"&gt;...&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now lets take that same example and see what it would look like in Rust.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;remove_database&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;database_name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;stmt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="nf"&gt;.prepare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nd"&gt;format!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"DROP DATABASE {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;database_name&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;stmt&lt;/span&gt;&lt;span class="nf"&gt;.execute&lt;/span&gt;&lt;span class="p"&gt;([])&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(())&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Rust, this function is &lt;strong&gt;&lt;em&gt;private by default&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In order for this function to be public, we would have to declare it public:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;remove_database&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;conn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;database_name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="o"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This example is a simple scoping error, or laziness.&lt;/p&gt;

&lt;p&gt;It's easy to miss, but Rust doesn't let you make this mistake.&lt;/p&gt;

&lt;p&gt;"Okay, so it's private by default, big deal. Theres other ways of improperly accessing functions and abusing them."&lt;/p&gt;

&lt;p&gt;Lets look at another example from the MITRE site:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Android code&lt;/span&gt;
&lt;span class="nd"&gt;@Override&lt;/span&gt;
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="nf"&gt;shouldOverrideUrlLoading&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;WebView&lt;/span&gt; &lt;span class="n"&gt;view&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;substring&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;equalsIgnoreCase&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"examplescheme:"&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;substring&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="o"&gt;).&lt;/span&gt;&lt;span class="na"&gt;equalsIgnoreCase&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"getUserInfo"&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;writeDataToView&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;view&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;UserData&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;This Android app intercepts the URL loading within a WebView and perform special actions if a particular URL scheme is used, thus allowing the Javascript within the WebView to communicate with the application."&lt;/p&gt;

&lt;p&gt;A call into native code can then be initiated by passing parameters within the URL:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;examplescheme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//method?parameter=value&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Because the application does not check the source, a malicious website loaded within this WebView has the same access to the API as a trusted site.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You see where this is already going.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;should_override_url_loading&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// 1.&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="nf"&gt;.starts_with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"examplescheme:"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// 2.&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;rest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="nf"&gt;.strip_prefix&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"examplescheme:"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.unwrap_or&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="c1"&gt;// 3.&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;rest&lt;/span&gt;&lt;span class="nf"&gt;.starts_with&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"getUserInfo"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// 4.&lt;/span&gt;
            &lt;span class="nf"&gt;write_data_to_view&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;UserData&lt;/span&gt; &lt;span class="p"&gt;{});&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 5.&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 6.&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;true&lt;/span&gt; &lt;span class="c1"&gt;// 7.&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Verify the source of the URL&lt;/li&gt;
&lt;li&gt;Source verification logic can be added here if needed. For simplicity, we assume all URLs with the &lt;code&gt;"examplescheme:"&lt;/code&gt; prefix are trusted. We extract the method from the URL.&lt;/li&gt;
&lt;li&gt;Check if the method is "getUserInfo"&lt;/li&gt;
&lt;li&gt;Write data to the view (assuming UserData is sanitized)&lt;/li&gt;
&lt;li&gt;Allow URL to load&lt;/li&gt;
&lt;li&gt;Do not override the URL.&lt;/li&gt;
&lt;li&gt;Default behavior: do not override the URL&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Not the prettiest Rust code, but it gives the general idea. &lt;/p&gt;

&lt;p&gt;We're using string slices &lt;code&gt;&amp;amp;str&lt;/code&gt; that require us to know the length of the string at compile time. &lt;/p&gt;

&lt;p&gt;In this way, Rust forces us to do bounds checking.&lt;/p&gt;

&lt;p&gt;If the string length we receive does not match the string length we expect, Rust will pitch a fit. These are the kinds of things people are talking about when they tell you "Rust helps you build good habits."&lt;/p&gt;

&lt;p&gt;Rust will not compile code if its wrong and forces you to think about what your code is doing and why it's doing it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Looking at Routing Abuse
&lt;/h2&gt;

&lt;p&gt;We can take it another step further.&lt;/p&gt;

&lt;p&gt;According to the analysis, web routing and path abuse tied for second with memory corruption issues. &lt;/p&gt;

&lt;p&gt;What is web path and routing abuse?&lt;/p&gt;

&lt;p&gt;Its a large category to define. One example is &lt;a href="https://cwe.mitre.org/data/definitions/22.html"&gt;MITRE CWE-22&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.&lt;/p&gt;

&lt;p&gt;Many file operations are intended to take place within a restricted directory. By using special elements such as ".." and "/" separators, attackers can escape outside of the restricted location to access files or directories that are elsewhere on the system. One of the most common special elements is the "../" sequence, which in most modern operating systems is interpreted as the parent directory of the current location. This is referred to as relative path traversal. Path traversal also covers the use of absolute pathnames such as "/usr/local/bin", which may also be useful in accessing unexpected files. This is referred to as absolute path traversal.&lt;/p&gt;

&lt;p&gt;In many programming languages, the injection of a null byte (the 0 or NUL) may allow an attacker to truncate a generated filename to widen the scope of attack. For example, the product may add ".txt" to any pathname, thus limiting the attacker to text files, but a null injection may effectively remove this restriction.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Web path and routing abuse happens when an attacker manipulates file paths or URLs in a way that allows them to access files or directories outside of the intended area.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In this example, the path to a dictionary file is read from a system property and used to initialize a File object:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;filename&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getProperty&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"com.domain.application.dictionaryFile"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;  
&lt;span class="nc"&gt;File&lt;/span&gt; &lt;span class="n"&gt;dictionaryFile&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;File&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;However, the path is not validated or modified to prevent it from containing relative or absolute path sequences before creating the File object. This allows anyone who can control the system property to determine what file is used. Ideally, the path should be resolved relative to some kind of application or user home directory.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We can rewrite the code in Rust using &lt;code&gt;PathBuf&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;path&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;PathBuf&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Get the value of the "com.domain.application.dictionaryFile" property&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;filename&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;match&lt;/span&gt; &lt;span class="nn"&gt;env&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"com.domain.application.dictionaryFile"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;val&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nf"&gt;Err&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nd"&gt;eprintln!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Error: Property 'com.domain.application.dictionaryFile' not found"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="c1"&gt;// Create a PathBuf representing the file path&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;dictionary_file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;PathBuf&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// You can perform further operations with the `dictionary_file` PathBuf&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Dictionary file path: {:?}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dictionary_file&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We use Rust's strong type-safety to represent a path using &lt;code&gt;PathBuf&lt;/code&gt;, ensuring that the paths are treated as filesystem paths and are subject to filesystem semantics.&lt;/p&gt;

&lt;p&gt;Rust's type system performs extensive compile-time checks, ensuring that operations on &lt;code&gt;PathBuf&lt;/code&gt; instances are type-safe and adhere to Rust's ownership and borrowing rules. This reduces the likelihood of runtime errors or vulnerabilities resulting from incorrect path manipulation.&lt;/p&gt;

&lt;h2&gt;
  
  
  The hero we need
&lt;/h2&gt;

&lt;p&gt;Rust has inherent qualities that make it safer to use than the average language.&lt;/p&gt;

&lt;p&gt;Rust may not save us, but the ideas it embodies will.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Private by default&lt;/li&gt;
&lt;li&gt;Immutable by default&lt;/li&gt;
&lt;li&gt;Type-safety checked at compile time&lt;/li&gt;
&lt;li&gt;Borrow checker and ownership model reducing memory corruption&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Rust doesn't rely on the developer to put in place all the details. It lifts responsibility from the developer so they can worry more on developing and less on safety/correctness. &lt;/p&gt;

&lt;p&gt;Imagine using a language that prevents these kind of vulnerabilities.&lt;/p&gt;

&lt;p&gt;Where we pass around immutable types, private functions by default, and types checked at compile time.&lt;/p&gt;

&lt;p&gt;Why don't we expect this from other languages?&lt;/p&gt;

&lt;p&gt;Why do we talk about around programming languages as if theres not a way to improve their inherent security as well?&lt;/p&gt;

&lt;p&gt;Besides all the recommendations Horizon made, programming languages should also be among them.&lt;/p&gt;

&lt;p&gt;We should expect all our languages to be safer.&lt;/p&gt;

</description>
      <category>rust</category>
    </item>
    <item>
      <title>Learn Git in 10 Minutes</title>
      <dc:creator>Glitchbyte</dc:creator>
      <pubDate>Sun, 05 Nov 2023 23:21:15 +0000</pubDate>
      <link>https://dev.to/glitchbyte/learn-git-in-10-minutes-4jj9</link>
      <guid>https://dev.to/glitchbyte/learn-git-in-10-minutes-4jj9</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbj0d9bnhqyyr6s4al7cw.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbj0d9bnhqyyr6s4al7cw.jpg" alt="Image of Git" width="800" height="530"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Every developer needs to learn Git. It's how we version control our code. By using git, we can step through every change we've ever made, forward and backward in time. &lt;/p&gt;

&lt;p&gt;This is crucial when mistakes are made. Instead of having to rewrite everything manually, you can simply revert your changes or hop to an earlier commit. &lt;/p&gt;

&lt;p&gt;It's only going to take us 10 minutes to cover 90% of git's usage.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installing Git
&lt;/h3&gt;

&lt;p&gt;First, we need to make sure git is installed on our system.&lt;/p&gt;

&lt;p&gt;Windows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Using winget in a powershell window&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;winget&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;install&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;git-all&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="c"&gt;# Chocolatey&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;chocolatey&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;install&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;git-all&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;MacOS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Using Homebrew&lt;/span&gt;
brew &lt;span class="nb"&gt;install &lt;/span&gt;git-all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Linux:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;// Ubuntu/Debian
apt &lt;span class="nb"&gt;install &lt;/span&gt;git-all

// Arch
pacman &lt;span class="nt"&gt;-Sy&lt;/span&gt; git-all

// CentOS/Fedora
yum &lt;span class="nb"&gt;install &lt;/span&gt;git-all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can find more info about &lt;a href="https://git-scm.com/book/en/v2/Getting-Started-Installing-Git"&gt;installing git here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Starting a git repo
&lt;/h3&gt;

&lt;p&gt;We'll start by creating a new project. In my case, Ill be starting a new repo for a NES emulator I'll be writing in C. If you dont know where to store your projects, create a &lt;code&gt;projects&lt;/code&gt; directory wherever you know you'll find it.&lt;/p&gt;

&lt;p&gt;Start your own project and name it whatever you'd like.&lt;/p&gt;

&lt;p&gt;I'll be naming my project &lt;code&gt;DrNES&lt;/code&gt; and moving into the directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Init project&lt;/span&gt;
&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; DrNES

&lt;span class="c"&gt;# Change dir into DrNES&lt;/span&gt;
&lt;span class="nb"&gt;cd &lt;/span&gt;DrNES
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that we have our project directory created and we're inside of it, we can start a git repo.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Start a git repo&lt;/span&gt;
git init

&lt;span class="c"&gt;# Check for .git directory&lt;/span&gt;
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-al&lt;/span&gt; .git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes the project directory we created into a git repo. &lt;/p&gt;

&lt;h3&gt;
  
  
  The Basics of Git
&lt;/h3&gt;

&lt;p&gt;From here, we can create a few files for git to find.&lt;/p&gt;

&lt;p&gt;In my case, Im going to create a source &lt;code&gt;src&lt;/code&gt; folder with &lt;code&gt;main.c&lt;/code&gt; in it and a &lt;code&gt;README.md&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This is going to lay the base file structure for my repo.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Create README&lt;/span&gt;
&lt;span class="nb"&gt;touch &lt;/span&gt;README.md

&lt;span class="c"&gt;# Make src folder&lt;/span&gt;
&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; src

&lt;span class="c"&gt;# Add main.c to src&lt;/span&gt;
&lt;span class="nb"&gt;touch &lt;/span&gt;src/main.c
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For now these will be empty files.&lt;/p&gt;

&lt;h4&gt;
  
  
  Git Status
&lt;/h4&gt;

&lt;p&gt;If we do a &lt;code&gt;git status&lt;/code&gt;, we will see what git is currently tracking for changes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git status

&lt;span class="c"&gt;# Output&lt;/span&gt;
On branch main

No commits yet

Untracked files:
  &lt;span class="o"&gt;(&lt;/span&gt;use &lt;span class="s2"&gt;"git add &amp;lt;file&amp;gt;..."&lt;/span&gt; to include &lt;span class="k"&gt;in &lt;/span&gt;what will be committed&lt;span class="o"&gt;)&lt;/span&gt;
        README.md
        src/

nothing added to commit but untracked files present &lt;span class="o"&gt;(&lt;/span&gt;use &lt;span class="s2"&gt;"git add"&lt;/span&gt; to track&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Git Add
&lt;/h4&gt;

&lt;p&gt;In order for git to start tracking these files, we need to use &lt;code&gt;git add&lt;/code&gt;. This command can be used to add individual files or all files in the directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Add one file to track&lt;/span&gt;
git add README.md

&lt;span class="c"&gt;# Add everything in repo to track&lt;/span&gt;
&lt;span class="c"&gt;# The '.' means to add everything in this directory&lt;/span&gt;
git add &lt;span class="nb"&gt;.&lt;/span&gt;

&lt;span class="c"&gt;# Output&lt;/span&gt;
On branch main

No commits yet

Changes to be committed:
  &lt;span class="o"&gt;(&lt;/span&gt;use &lt;span class="s2"&gt;"git rm --cached &amp;lt;file&amp;gt;..."&lt;/span&gt; to unstage&lt;span class="o"&gt;)&lt;/span&gt;
        new file:   README.md
        new file:   src/main.c
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In my case, I use &lt;code&gt;git add .&lt;/code&gt; to make git track everything in my directory.&lt;/p&gt;

&lt;h4&gt;
  
  
  Git Commit
&lt;/h4&gt;

&lt;p&gt;Once we've added our files to track, we need to commit to the changes. We use the &lt;code&gt;git commit&lt;/code&gt; command to do this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Commit our changes&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"init commit"&lt;/span&gt;

&lt;span class="c"&gt;# Output&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;main &lt;span class="o"&gt;(&lt;/span&gt;root-commit&lt;span class="o"&gt;)&lt;/span&gt; 1b13406] init commit
 2 files changed, 0 insertions&lt;span class="o"&gt;(&lt;/span&gt;+&lt;span class="o"&gt;)&lt;/span&gt;, 0 deletions&lt;span class="o"&gt;(&lt;/span&gt;-&lt;span class="o"&gt;)&lt;/span&gt;
 create mode 100644 README.md
 create mode 100644 src/main.c
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Whenever we commit to our changes, we have to add a message to the commit for the &lt;code&gt;git log&lt;/code&gt;. If we just did &lt;code&gt;git commit&lt;/code&gt;, it would drop us into vim or whatever other editor you have set as the default.&lt;/p&gt;

&lt;p&gt;To bypass being dropped into vim, we use &lt;code&gt;git commit -m "My message here"&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  Git Push
&lt;/h4&gt;

&lt;p&gt;Now we can use &lt;code&gt;git push&lt;/code&gt; to push our changes to a remote repo.&lt;/p&gt;

&lt;p&gt;To that, however, we need a remote repo, otherwise we will get the following error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Push git changes&lt;/span&gt;
git push

&lt;span class="c"&gt;# Output&lt;/span&gt;
fatal: No configured push destination.
Either specify the URL from the command-line or configure a remote repository using

    git remote add &amp;lt;name&amp;gt; &amp;lt;url&amp;gt;

and &lt;span class="k"&gt;then &lt;/span&gt;push using the remote name

    git push &amp;lt;name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Setting up a Github
&lt;/h4&gt;

&lt;p&gt;At the moment, we dont have a remote repo to push our changes to.&lt;/p&gt;

&lt;p&gt;Thats where something like &lt;a href="https://github.com"&gt;Github&lt;/a&gt; or &lt;a href="https://github.com"&gt;Gitlab&lt;/a&gt; come in.&lt;/p&gt;

&lt;p&gt;These are remote servers that allow us to host and share our code with the world, provided by those two companies.&lt;/p&gt;

&lt;p&gt;For my repo, Ill be using Github. I already have an account, but it should be simple to sign up for one.&lt;/p&gt;

&lt;p&gt;Once you do, navigate to the "Repositories" tab and click "New" in top right hand corner.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd76b9jcyv6i01e3l8tsh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fd76b9jcyv6i01e3l8tsh.png" alt="Create a new repo photo" width="800" height="148"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That will take you to a "Create new repository" page.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz2gt5huov67en9bhr704.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz2gt5huov67en9bhr704.png" alt="Options to fill out for creating new repo on Github" width="800" height="1062"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On this page, we want to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Give the repo a name&lt;/li&gt;
&lt;li&gt;Add a description&lt;/li&gt;
&lt;li&gt;Set repo to public or private (your choice)&lt;/li&gt;
&lt;li&gt;Click "Create repository"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We do &lt;em&gt;not&lt;/em&gt; want to initialize the repo with a README, because we already have a README. As of right now, I dont want to add a &lt;code&gt;.gitignore&lt;/code&gt; or license. I want this repo to be blank.&lt;/p&gt;

&lt;p&gt;If we didnt already have a repo to push to Github, I would have added the README, added &lt;code&gt;.gitignore&lt;/code&gt;, and selected a license.&lt;/p&gt;

&lt;p&gt;After we've created our Github repo, its going to ask whether we want to "create a new repo" or "push an existing one".&lt;/p&gt;

&lt;p&gt;We're doing the latter, so we will follow those directions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4oomjt715svp0x3vg5x1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4oomjt715svp0x3vg5x1.png" alt="Pushing an existing repo to Github" width="800" height="820"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We do this in our terminal where our project repo is. &lt;/p&gt;

&lt;p&gt;Lets look at each command:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git remote add origin github.com/User/myrepo.git&lt;/code&gt; tells our local git repo where to find our remote git repo.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git branch -M main&lt;/code&gt; creates a main branch in our local repo. This main branch should be protected, more on that later. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git push -u origin main&lt;/code&gt; allows us to push our changes to the upstream repo main branch &lt;code&gt;-u origin main&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Our &lt;code&gt;git push&lt;/code&gt; may error out.&lt;/p&gt;

&lt;p&gt;This is because we have to define an authentication method with Github.&lt;/p&gt;

&lt;p&gt;We have two options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/about-authentication-to-github#ssh"&gt;Use the Github CLI to authenticate&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent"&gt;Create an SSH key and add it to Github&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once we have that situated, we can try our &lt;code&gt;git push&lt;/code&gt; again.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Push changes to Github&lt;/span&gt;
git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin main

&lt;span class="c"&gt;# Output&lt;/span&gt;
Enumerating objects: 4, &lt;span class="k"&gt;done&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
Counting objects: 100% &lt;span class="o"&gt;(&lt;/span&gt;4/4&lt;span class="o"&gt;)&lt;/span&gt;, &lt;span class="k"&gt;done&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
Delta compression using up to 10 threads
Compressing objects: 100% &lt;span class="o"&gt;(&lt;/span&gt;2/2&lt;span class="o"&gt;)&lt;/span&gt;, &lt;span class="k"&gt;done&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
Writing objects: 100% &lt;span class="o"&gt;(&lt;/span&gt;4/4&lt;span class="o"&gt;)&lt;/span&gt;, 301 bytes | 301.00 KiB/s, &lt;span class="k"&gt;done&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
Total 4 &lt;span class="o"&gt;(&lt;/span&gt;delta 0&lt;span class="o"&gt;)&lt;/span&gt;, reused 0 &lt;span class="o"&gt;(&lt;/span&gt;delta 0&lt;span class="o"&gt;)&lt;/span&gt;, pack-reused 0
To https://github.com/0xGlitchbyte/DrNES.git
 &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;new branch]      master -&amp;gt; master
branch &lt;span class="s1"&gt;'master'&lt;/span&gt; &lt;span class="nb"&gt;set &lt;/span&gt;up to track &lt;span class="s1"&gt;'origin/master'&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we go back to Github, we should see something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4l2thbp2li4fi7l90xcx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4l2thbp2li4fi7l90xcx.png" alt="What the repo looks like after being pushed to Github" width="800" height="485"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's how we know our repo has been successfully pushed.&lt;/p&gt;

&lt;h4&gt;
  
  
  Best Practices for Git
&lt;/h4&gt;

&lt;p&gt;Now that we have successfully added, committed, and pushed changes to Github, we want to start developing.&lt;/p&gt;

&lt;p&gt;Remember I said we want to protect &lt;code&gt;main&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;Best practice is to develop on a separate branch besides &lt;code&gt;main&lt;/code&gt; so we dont push changes that will mess up the &lt;code&gt;main&lt;/code&gt; branch.&lt;/p&gt;

&lt;p&gt;So we will create a &lt;code&gt;dev&lt;/code&gt; branch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Create dev branch&lt;/span&gt;
git branch dev

&lt;span class="c"&gt;# Switch to dev branch&lt;/span&gt;
git switch dev

&lt;span class="c"&gt;# Push changes from local dev to remote dev&lt;/span&gt;
git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin dev

&lt;span class="c"&gt;# Output&lt;/span&gt;
Enumerating objects: 7, &lt;span class="k"&gt;done&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
Counting objects: 100% &lt;span class="o"&gt;(&lt;/span&gt;7/7&lt;span class="o"&gt;)&lt;/span&gt;, &lt;span class="k"&gt;done&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
Delta compression using up to 10 threads
Compressing objects: 100% &lt;span class="o"&gt;(&lt;/span&gt;3/3&lt;span class="o"&gt;)&lt;/span&gt;, &lt;span class="k"&gt;done&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
Writing objects: 100% &lt;span class="o"&gt;(&lt;/span&gt;4/4&lt;span class="o"&gt;)&lt;/span&gt;, 410 bytes | 410.00 KiB/s, &lt;span class="k"&gt;done&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
Total 4 &lt;span class="o"&gt;(&lt;/span&gt;delta 0&lt;span class="o"&gt;)&lt;/span&gt;, reused 0 &lt;span class="o"&gt;(&lt;/span&gt;delta 0&lt;span class="o"&gt;)&lt;/span&gt;, pack-reused 0
remote:
remote: Create a pull request &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="s1"&gt;'dev'&lt;/span&gt; on GitHub by visiting:
remote:      https://github.com/0xGlitchbyte/DrNES/pull/new/dev
remote:
To https://github.com/0xGlitchbyte/DrNES.git
 &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;new branch]      dev -&amp;gt; dev
branch &lt;span class="s1"&gt;'dev'&lt;/span&gt; &lt;span class="nb"&gt;set &lt;/span&gt;up to track &lt;span class="s1"&gt;'origin/dev'&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now when we &lt;code&gt;git add&lt;/code&gt; and &lt;code&gt;git commit&lt;/code&gt; on this branch, it wont affect our main branch.&lt;/p&gt;

&lt;p&gt;Since main is our source of truth branch, where all production ready code gets push to, we need to do a &lt;a href="https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request"&gt;pull request in Github&lt;/a&gt; to merge &lt;code&gt;dev&lt;/code&gt; into &lt;code&gt;main&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Once all changes have been approved and the pull request has been merged into &lt;code&gt;main&lt;/code&gt;, other people can use &lt;code&gt;git pull&lt;/code&gt; to get the latest changes.&lt;/p&gt;

&lt;p&gt;You can also setup a &lt;code&gt;.gitignore&lt;/code&gt; file in your directory. This file will allow you to exclude files and file types to be excluded from being added for staging commits.&lt;/p&gt;

&lt;h4&gt;
  
  
  Different Git commands to be aware of
&lt;/h4&gt;

&lt;h4&gt;
  
  
  Git Clone
&lt;/h4&gt;

&lt;p&gt;If you find a repo you come across that you'd like to contribute to, you can use &lt;code&gt;git clone&lt;/code&gt; to pull it from a remote server (i.e. Github) to your local machine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Cloning the DrNES repo with HTTPS&lt;/span&gt;
git clone https://github.com/0xGlitchbyte/DrNES.git

&lt;span class="c"&gt;# Cloning with SSH and changing the folder name&lt;/span&gt;
git clone git@github.com:0xGlitchbyte/DrNES.git dr_nes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Git Fetch
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;git fetch&lt;/code&gt; updates your remote-tracking branches under &lt;code&gt;refs/remotes/&amp;lt;remote&amp;gt;/&lt;/code&gt;. This operation is safe to run at any time since it never changes any of your local branches under &lt;code&gt;refs/heads&lt;/code&gt;. This is used instead of &lt;code&gt;pull&lt;/code&gt; when you just want to update the remote references.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git fetch 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Git Remove
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;git rm&lt;/code&gt; will remove files from your git repo and filesystem, if you specify it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Remove files from cache&lt;/span&gt;
git &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;--cache&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Git Log
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;git log&lt;/code&gt; allows us to see a log of our commits. This is useful when we'd like to view changes passed commits may have done, or to switch to a different commit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git log

&lt;span class="c"&gt;# Output&lt;/span&gt;
commit 124d9e29ac5ddac77c911c83c2100ca54f9d04d0 &lt;span class="o"&gt;(&lt;/span&gt;HEAD -&amp;gt; dev, origin/dev&lt;span class="o"&gt;)&lt;/span&gt;
Author: 0xGlitchbyte &amp;lt;49317853+0xGlitchbyte@users.noreply.github.com&amp;gt;
Date:   Sun Nov 5 15:40:47 2023 &lt;span class="nt"&gt;-0500&lt;/span&gt;

    added hello world

commit 1b134069e7dd4469b3439b02b82b2a0d9db4e535 &lt;span class="o"&gt;(&lt;/span&gt;origin/master, master&lt;span class="o"&gt;)&lt;/span&gt;
Author: 0xGlitchbyte &amp;lt;49317853+0xGlitchbyte@users.noreply.github.com&amp;gt;
Date:   Sun Nov 5 14:22:22 2023 &lt;span class="nt"&gt;-0500&lt;/span&gt;

    init commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Git Show
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;git show&lt;/code&gt; shows us the details and metadata of our last commit&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git show

&lt;span class="c"&gt;# Output&lt;/span&gt;
commit 124d9e29ac5ddac77c911c83c2100ca54f9d04d0 &lt;span class="o"&gt;(&lt;/span&gt;HEAD -&amp;gt; dev, origin/dev&lt;span class="o"&gt;)&lt;/span&gt;
Author: 0xGlitchbyte &amp;lt;49317853+0xGlitchbyte@users.noreply.github.com&amp;gt;
Date:   Sun Nov 5 15:40:47 2023 &lt;span class="nt"&gt;-0500&lt;/span&gt;

    added hello world

diff &lt;span class="nt"&gt;--git&lt;/span&gt; a/src/main.c b/src/main.c
index e69de29..18e3a28 100644
&lt;span class="nt"&gt;---&lt;/span&gt; a/src/main.c
+++ b/src/main.c
@@ &lt;span class="nt"&gt;-0&lt;/span&gt;,0 +1,6 @@
+#include &amp;lt;stdio.h&amp;gt;
+
+int main&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
+  &lt;span class="nb"&gt;printf&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Hello World!"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
+  &lt;span class="k"&gt;return &lt;/span&gt;0&lt;span class="p"&gt;;&lt;/span&gt;
+&lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;(&lt;/span&gt;END&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Git Diff
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;git diff&lt;/code&gt; allows us to view the difference between two commits.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Will compare last commit to current changes&lt;/span&gt;
git diff

&lt;span class="c"&gt;# Output&lt;/span&gt;
diff &lt;span class="nt"&gt;--git&lt;/span&gt; a/src/main.c b/src/main.c
index 18e3a28..139eeca 100644
&lt;span class="nt"&gt;---&lt;/span&gt; a/src/main.c
+++ b/src/main.c
@@ &lt;span class="nt"&gt;-1&lt;/span&gt;,6 +1,9 @@
 &lt;span class="c"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;

 int main&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
+  // I have added some comments here
   &lt;span class="nb"&gt;printf&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Hello World!"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
+
+  // And here!
   &lt;span class="k"&gt;return &lt;/span&gt;0&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;(&lt;/span&gt;END&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Git Stash
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;git stash&lt;/code&gt; allows us to stash away any changes we have made in our current branch. This is useful when we want to keep our changes, but go back to a clean working directory to try something else.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git stash

&lt;span class="c"&gt;# Output&lt;/span&gt;
Saved working directory and index state WIP on dev: 124d9e2 added hello world
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Git Reset
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;git reset&lt;/code&gt; will reset our changes back to a clean working directory without saving them.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  Git Branch
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;git branch&lt;/code&gt; will show a list of all current branches in the git repo.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch

&lt;span class="c"&gt;# Output&lt;/span&gt;
&lt;span class="k"&gt;*&lt;/span&gt; dev
  master
&lt;span class="o"&gt;(&lt;/span&gt;END&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Git Merge
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;git merge&lt;/code&gt; allows you to join two development histories together. You use &lt;code&gt;git merge&lt;/code&gt; when you want to reconcile other branches into &lt;code&gt;main&lt;/code&gt;, for example. When you merge histories, its important to note you will have to reconcile any conflicting differences between the two.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Merge dev into master with a message&lt;/span&gt;
git merge &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"My message here"&lt;/span&gt; dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Git Rebase
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;git rebase&lt;/code&gt; allows you to easily change a series of commits, modifying the history of your repository. You can reorder, edit, or squash commits together. You may not want to merge back into &lt;code&gt;main&lt;/code&gt; just yet, so you can pull a version, rebase, and continue development from the point you rebased.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git switch dev
git rebase main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Git Restore
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;git restore&lt;/code&gt; allows you to restore or discard unstaged files in your git repo.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Restore a file&lt;/span&gt;
git restore filename.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Git -h
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;git -h&lt;/code&gt; is shorthand for &lt;code&gt;git --help&lt;/code&gt;. It will list all the options you can use with git. &lt;code&gt;man git&lt;/code&gt; will give you the manual page on linux for git.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git &lt;span class="nt"&gt;-h&lt;/span&gt;

usage: git &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-v&lt;/span&gt; | &lt;span class="nt"&gt;--version&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-h&lt;/span&gt; | &lt;span class="nt"&gt;--help&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-C&lt;/span&gt; &amp;lt;path&amp;gt;] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-c&lt;/span&gt; &amp;lt;name&amp;gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;value&amp;gt;]
           &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;--exec-path&lt;/span&gt;&lt;span class="o"&gt;[=&lt;/span&gt;&amp;lt;path&amp;gt;]] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;--html-path&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;--man-path&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;--info-path&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
           &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;-p&lt;/span&gt; | &lt;span class="nt"&gt;--paginate&lt;/span&gt; | &lt;span class="nt"&gt;-P&lt;/span&gt; | &lt;span class="nt"&gt;--no-pager&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;--no-replace-objects&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;--bare&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
           &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;--git-dir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;path&amp;gt;] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;--work-tree&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;path&amp;gt;] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;--namespace&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;name&amp;gt;]
           &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;--super-prefix&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;path&amp;gt;] &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="nt"&gt;--config-env&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;name&amp;gt;&lt;span class="o"&gt;=&lt;/span&gt;&amp;lt;envvar&amp;gt;]
           &amp;lt;&lt;span class="nb"&gt;command&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&amp;lt;args&amp;gt;]

These are common Git commands used &lt;span class="k"&gt;in &lt;/span&gt;various situations:

start a working area &lt;span class="o"&gt;(&lt;/span&gt;see also: git &lt;span class="nb"&gt;help &lt;/span&gt;tutorial&lt;span class="o"&gt;)&lt;/span&gt;
   clone     Clone a repository into a new directory
   init      Create an empty Git repository or reinitialize an existing one

work on the current change &lt;span class="o"&gt;(&lt;/span&gt;see also: git &lt;span class="nb"&gt;help &lt;/span&gt;everyday&lt;span class="o"&gt;)&lt;/span&gt;
   add       Add file contents to the index
   &lt;span class="nb"&gt;mv        &lt;/span&gt;Move or rename a file, a directory, or a symlink
   restore   Restore working tree files
   &lt;span class="nb"&gt;rm        &lt;/span&gt;Remove files from the working tree and from the index

examine the &lt;span class="nb"&gt;history &lt;/span&gt;and state &lt;span class="o"&gt;(&lt;/span&gt;see also: git &lt;span class="nb"&gt;help &lt;/span&gt;revisions&lt;span class="o"&gt;)&lt;/span&gt;
   bisect    Use binary search to find the commit that introduced a bug
   diff      Show changes between commits, commit and working tree, etc
   &lt;span class="nb"&gt;grep      &lt;/span&gt;Print lines matching a pattern
   log       Show commit logs
   show      Show various types of objects
   status    Show the working tree status

grow, mark and tweak your common &lt;span class="nb"&gt;history
   &lt;/span&gt;branch    List, create, or delete branches
   commit    Record changes to the repository
   merge     Join two or more development histories together
   rebase    Reapply commits on top of another base tip
   reset     Reset current HEAD to the specified state
   switch    Switch branches
   tag       Create, list, delete or verify a tag object signed with GPG

collaborate &lt;span class="o"&gt;(&lt;/span&gt;see also: git &lt;span class="nb"&gt;help &lt;/span&gt;workflows&lt;span class="o"&gt;)&lt;/span&gt;
   fetch     Download objects and refs from another repository
   pull      Fetch from and integrate with another repository or a &lt;span class="nb"&gt;local &lt;/span&gt;branch
   push      Update remote refs along with associated objects

&lt;span class="s1"&gt;'git help -a'&lt;/span&gt; and &lt;span class="s1"&gt;'git help -g'&lt;/span&gt; list available subcommands and some
concept guides. See &lt;span class="s1"&gt;'git help &amp;lt;command&amp;gt;'&lt;/span&gt; or &lt;span class="s1"&gt;'git help &amp;lt;concept&amp;gt;'&lt;/span&gt;
to &lt;span class="nb"&gt;read &lt;/span&gt;about a specific subcommand or concept.
See &lt;span class="s1"&gt;'git help git'&lt;/span&gt; &lt;span class="k"&gt;for &lt;/span&gt;an overview of the system.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;Git is an important tool to learn, but its not difficult to learn.&lt;/p&gt;

&lt;p&gt;The majority of the time, youll be using these commands:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;git add&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git commit -m&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git push&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git pull&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git clone&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The rest are good to learn, but will be used on a case by case basis.&lt;/p&gt;

&lt;p&gt;You can use git on any files you'd like to version control, from code to text documents.&lt;/p&gt;

&lt;p&gt;The more you practice, the better youll get at it.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>git</category>
      <category>development</category>
    </item>
  </channel>
</rss>
