<?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: Mustafa Hashmani</title>
    <description>The latest articles on DEV Community by Mustafa Hashmani (@mustafahashmani).</description>
    <link>https://dev.to/mustafahashmani</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%2F430247%2F20207cb6-5ac8-456c-8af6-b0bcd16f6b66.png</url>
      <title>DEV Community: Mustafa Hashmani</title>
      <link>https://dev.to/mustafahashmani</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mustafahashmani"/>
    <language>en</language>
    <item>
      <title>Rebasing: The Scariest Git Command?</title>
      <dc:creator>Mustafa Hashmani</dc:creator>
      <pubDate>Wed, 23 Aug 2023 18:12:49 +0000</pubDate>
      <link>https://dev.to/mustafahashmani/rebasing-the-scariest-git-command-439i</link>
      <guid>https://dev.to/mustafahashmani/rebasing-the-scariest-git-command-439i</guid>
      <description>&lt;h2&gt;
  
  
  Why do we need Rebasing?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;I'm working on a collaborative project&lt;/li&gt;
&lt;li&gt;I make a feature branch!&lt;/li&gt;
&lt;li&gt;I do some work on the branch and some more work on the branch&lt;/li&gt;
&lt;li&gt;Meanwhile, Master has new work on it and my feature branch doesn't have this work!&lt;/li&gt;
&lt;li&gt;I merge master into feature and this results in a new merge commit&lt;/li&gt;
&lt;li&gt;I keep working on my feature branch and a coworker adds new work to master&lt;/li&gt;
&lt;li&gt;I merge master in to my feature branch and this results in yet another merge commit!&lt;/li&gt;
&lt;li&gt;The feature branch has a bunch of merge commits. If the master branch is very active, my feature branch's history is muddied&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Why Rebase?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;We get a much cleaner project history.&lt;/li&gt;
&lt;li&gt;No unnecessary merge commits! &lt;/li&gt;
&lt;li&gt;We end up with a linear project history.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Rebasing
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;We can instead rebase the feature branch onto the master branch. This moves the entire feature branch so that it BEGINS at the tip of the master branch. All of the work is still there, but &lt;strong&gt;we have re-written history&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Instead of using a merge commit, rebasing rewrites history by &lt;strong&gt;creating new commits&lt;/strong&gt; for each of the original feature branch commits.&lt;/li&gt;
&lt;li&gt;It is not going to change the master branch, instead it is going to rewrite history by taking the feature branch commits and creating new ones that are based on the originals and putting them all at the tip of the master branch&lt;/li&gt;
&lt;li&gt;We are &lt;strong&gt;BASING&lt;/strong&gt; that branch on the tip of the &lt;em&gt;master&lt;/em&gt; branch&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjb3utjdh7g2qh11w0ctu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjb3utjdh7g2qh11w0ctu.png" alt="Image"&gt;&lt;/a&gt;&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 feature
git rebase master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;There are two main ways to use the git rebase command:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;as an alternative to merging&lt;/li&gt;
&lt;li&gt;as a cleanup tool&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Warning&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Never rebase commits that have been shared with others. If you have already pushed commits up to Github...DO NOT rebase them unless you are positive no one on the team is using those commits.&lt;/li&gt;
&lt;li&gt;You do not want to rewrite any git history that other people already have. It's a pain to reconcile the alternate histories!&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Interactive Rebase
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Sometimes we want to rewrite, delete, rename, or even reorder commits (before sharing them). We can do this using git rebase!&lt;/li&gt;
&lt;li&gt;Running &lt;code&gt;git rebase&lt;/code&gt; with the &lt;strong&gt;-i&lt;/strong&gt; option will enter the interactive mode, which allows us to edit commits, add files, drop commits, etc. Note that we need to specify how far back we want to rewrite commits.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Also, notice that we are not rebasing onto another branch. Instead, we are rebasing a series of commits onto the HEAD they currently are based on.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   git rebase &lt;span class="nt"&gt;-i&lt;/span&gt; HEAD~4 &lt;span class="c"&gt;# go back four commits&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In our text editor, we'll see a list of commits alongside a list of commands that we can choose from. Here are a couple of the more commonly used commands:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;pick - use the commit&lt;/li&gt;
&lt;li&gt;reword - use the commit, but edit the commit message&lt;/li&gt;
&lt;li&gt;edit - use commit, but stop for amending&lt;/li&gt;
&lt;li&gt;fixup - use commit contents but meld it into previous&lt;/li&gt;
&lt;li&gt;commit and discard the commit message&lt;/li&gt;
&lt;li&gt;drop - remove commit&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>beginners</category>
      <category>100daysofcode</category>
    </item>
    <item>
      <title>The Different Types of Collaboration Workflows in Git</title>
      <dc:creator>Mustafa Hashmani</dc:creator>
      <pubDate>Tue, 22 Aug 2023 06:19:39 +0000</pubDate>
      <link>https://dev.to/mustafahashmani/the-different-types-of-collaboration-workflows-in-git-381m</link>
      <guid>https://dev.to/mustafahashmani/the-different-types-of-collaboration-workflows-in-git-381m</guid>
      <description>&lt;h2&gt;
  
  
  Centralized Workflow
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;AKA Everyone Works On Master/Main&lt;/li&gt;
&lt;li&gt;AKA The Most Basic Workflow Possible&lt;/li&gt;
&lt;li&gt;The simplest collaborative workflow is to have everyone work on the master branch (or main, or any other SINGLE branch).&lt;/li&gt;
&lt;li&gt;It's straightforward and can work for tiny teams, but it has quite a few shortcomings!&lt;/li&gt;
&lt;li&gt;Pamela, Forrest and David clone the repo&lt;/li&gt;
&lt;li&gt;Forrest gets to work on a new feature and pushes his work to Github&lt;/li&gt;
&lt;li&gt;At the same time, Pamela also worked on a new feature. She tries to push her new work up to Github, but she runs into trouble as the current branch is behind its remote counterpart. So she pulls to get the changes from origin master, merges them and then pushes them&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;David is working on a new feature, but is having some doubts. He'd like to share his commits with the rest of the team to start a discussion but before he can commit he has to pull from Github and merge them into master Now he can finally push his work up to Github. His teammates can pull to get his new commits.&lt;/p&gt;
&lt;h3&gt;
  
  
  The Problem
&lt;/h3&gt;

&lt;p&gt;While it's nice and easy to only work on the master branch,&lt;br&gt;
this leads to some serious issues on teams :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lots of time is spent resolving conflicts and merging code, especially as team size scales up.&lt;/li&gt;
&lt;li&gt;No one can work on anything without disturbing the main codebase. How do you try adding something radically different in? How do you experiment?&lt;/li&gt;
&lt;li&gt;The only way to collaborate on a feature together with another teammate is to push incomplete code to master. Other teammates now have broken code...&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Feature Branches
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Rather than working directly on master/main, all new development should be done on separate branches!

&lt;ul&gt;
&lt;li&gt;Treat master/main branch as the official project history&lt;/li&gt;
&lt;li&gt;Multiple teammates can collaborate on a single feature and share code back and forth without polluting the master/main branch&lt;/li&gt;
&lt;li&gt;Master/main branch won't contain broken code (or at least, it won't unless someone messes up)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Pamela, Forrest and David clone the repo&lt;/li&gt;
&lt;li&gt;David starts work on a new feature. He does all this work on a separate branch!&lt;/li&gt;
&lt;li&gt;David wants Pamela to take a look at his new feature. Instead of merging it into master, he just pushes his feature branch up to Github!&lt;/li&gt;
&lt;li&gt;Pamela is hard at work on her own new feature. Just like everyone else, she's working on a separate feature branch rather than master.&lt;/li&gt;
&lt;li&gt;Pamela hears from David that he wants her to take a look at his new work. She pulls down his feature branch from Github.&lt;/li&gt;
&lt;li&gt;Pamela takes a look at the code and makes a couple of improvements of her own. She adds/commits on the same feature branch.&lt;/li&gt;
&lt;li&gt;Pamela pushes up her new work on the add-dark-theme feature branch so that David can pull them down.&lt;/li&gt;
&lt;li&gt;David fetches from Github and sees that there is new work on the add dark theme branch. He pulls the changes down and continues work.&lt;/li&gt;
&lt;li&gt;David decides he is happy with the new feature, so he merges it into master!&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;David pushes up the updated master branch to Github. The others can now pull down the changes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Feature Branch Naming
&lt;/h3&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There are many different approaches for naming feature branches. Often you'll see branch names that include slashes like &lt;strong&gt;bug/fix-scroll&lt;/strong&gt; or &lt;strong&gt;feature/login-form&lt;/strong&gt; or &lt;strong&gt;feat/button/enable-pointer-events&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Specific teams and projects usually have their own branch naming conventions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Merging In Feature Branches
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;At some point, the new work on feature branches will need to be merged into the master branch! There are a couple of options for how to do this :

&lt;ul&gt;
&lt;li&gt;Merge at will, without any sort of discussion with teammates. JUST DO IT WHENEVER YOU WANT.&lt;/li&gt;
&lt;li&gt;Send an email or chat message or something to your team to discuss if the changes should be merged in.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pull Requests&lt;/strong&gt;!&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Pull Requests
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Pull Requests are a feature built into products like Github and Bitbucket. &lt;strong&gt;They are not native to Git itself&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;They allow developers to alert team-members to new work that needs to be reviewed. They provide a mechanism to approve or reject the work on a given branch. They also help facilitate discussion and feedback on the specified commits.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;"I have this new stuff I want to merge into the master branch...what do you all think about it?"&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  The Workflow
&lt;/h3&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1. Do some work locally on a feature branch
2. Push up the feature branch to Github
3. Open a pull request using the feature branch just pushed up to Github
4. Wait for the PR to be approved and merged. Start a discussion on the PR. This part depends on the team structure.

### Merging Pull Requests with Conflicts

- Just like any other merge, sometimes there are conflicts that need to be resolved when merging a pull request.
- You can perform the merge and fix the conflicts on the command line like normal, or you can use Github's interactive editor.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gUVjAuIH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dkkbrig2cmo8hmlkdud2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gUVjAuIH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dkkbrig2cmo8hmlkdud2.png" alt="Image" width="715" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Fork and Clone
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The "fork and clone" workflow is different from anything we've seen so far. Instead of just one centralized Github repository, every developer has their own Github repository in addition to the "main" repo.&lt;/li&gt;
&lt;li&gt;Developers make changes and push to their own forks before making pull requests.&lt;/li&gt;
&lt;li&gt;It's very commonly used on large open-source projects where there may be thousands of contributors with only a couple of maintainers.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;It allows a project maintainer to accept contributions from developers all around the world without having to add them as actual owners of the main project repository or worry about giving them permissions to push to the repo&lt;/p&gt;
&lt;h3&gt;
  
  
  Forking
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Github (and similar tools) allow us to create personal copies of other people’s repositories. We call those copies a "fork" of the original.&lt;/li&gt;
&lt;li&gt;When we fork a repo, we're basically asking Github "Make me my own copy of this repo please"&lt;/li&gt;
&lt;li&gt;As with pull requests, forking is not a Git feature. The ability to fork is implemented by Github.&lt;/li&gt;
&lt;li&gt;When you click on the &lt;strong&gt;fork&lt;/strong&gt; button on that repository, it will create a copy on your account&lt;/li&gt;
&lt;li&gt;Now that I've forked, I have my very own copy of the repo where I can do whatever I want!&lt;/li&gt;
&lt;li&gt;I can clone my fork and make changes, add features, and break things without fear of disturbing the original repository.&lt;/li&gt;
&lt;li&gt;If I do want to share my work, I can make a &lt;strong&gt;pull request&lt;/strong&gt; from my fork to the original repo.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Workflow
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt; When we clone a repo, Git automatically adds a remote 
called &lt;strong&gt;origin&lt;/strong&gt; that points to our forked repo on Github.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Next, I add a remote pointing to the original project repo &lt;br&gt;
(NOT the fork). This remote can be named anything, but &lt;br&gt;
you'll often see "&lt;strong&gt;upstream&lt;/strong&gt;" or "&lt;strong&gt;original&lt;/strong&gt;" used.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git remote add upstream &amp;lt;url&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;I do some new work locally. To share my changes with others, I cannot push to upstream. I don't have permission! But I can push to origin (my Github fork)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next, I can make a pull request from my fork on Github to the original project repository. Now I wait to hear from the project maintainers! Do they want me to make further changes? It turns out they accept and merge my pull request!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The next day, I get back to work. The official project repo now contains work done by other collaborators. I don't have their new work on my machine! I'm behind!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;All I need to do is &lt;strong&gt;pull from upstream&lt;/strong&gt; (the original repo) to get the latest changes in my local repo.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now I have the latest changes from the upstream repo! I can work on some new features locally without working about being out of date.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5yDwSZNB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ft9uypb60segijk6ne42.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5yDwSZNB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ft9uypb60segijk6ne42.png" alt="Image" width="783" height="441"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;### Summary
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ol&gt;
&lt;li&gt;I &lt;strong&gt;fork&lt;/strong&gt; the original project repo on Github&lt;/li&gt;
&lt;li&gt;I &lt;strong&gt;clone&lt;/strong&gt; my fork to my local machine&lt;/li&gt;
&lt;li&gt;I &lt;strong&gt;add a remote&lt;/strong&gt; pointing to the original project repo. This remote is often named &lt;em&gt;upstream&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;I &lt;strong&gt;make changes&lt;/strong&gt; and add/commit on a feature branch on my local machine&lt;/li&gt;
&lt;li&gt;I &lt;strong&gt;push&lt;/strong&gt; up my new feature branch to my forked repo(usually called origin)&lt;/li&gt;
&lt;li&gt;I &lt;strong&gt;open a pull request&lt;/strong&gt; to the original project repo containing the new work on my forked repo&lt;/li&gt;
&lt;li&gt;Hopefully, the pull request is accepted and my changes are merged in!&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Unveiling the Art of Sync: Mastering Fetching and Pulling in Git</title>
      <dc:creator>Mustafa Hashmani</dc:creator>
      <pubDate>Sun, 20 Aug 2023 11:39:17 +0000</pubDate>
      <link>https://dev.to/mustafahashmani/unveiling-the-art-of-sync-mastering-fetching-and-pulling-in-git-18g5</link>
      <guid>https://dev.to/mustafahashmani/unveiling-the-art-of-sync-mastering-fetching-and-pulling-in-git-18g5</guid>
      <description>&lt;h2&gt;
  
  
  How Cloning Works
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;After cloning there will be two branch references:

&lt;ol&gt;
&lt;li&gt;A regular branch reference that I can move around myself.(the default branch of the Github repo)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;origin/master&lt;/strong&gt;. This is a "&lt;strong&gt;Remote Tracking Branch&lt;/strong&gt;". It's a reference to the state of the master branch on the remote. I can't move this myself. It's like a bookmark pointing to the last known commit on the master branch on origin remote.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--s0RENLOK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y0ird8gysnx7ohixdhvu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--s0RENLOK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y0ird8gysnx7ohixdhvu.png" alt="Image" width="751" height="294"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Remote Tracking Branches
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;"At the time you last communicated with this remote repository, here is where x branch was pointing"&lt;/li&gt;
&lt;li&gt;They follow this pattern &lt;strong&gt;remote/branch&lt;/strong&gt;.

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;origin/master&lt;/strong&gt; references the state of the master branch on the remote repo named origin.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;upstream/logoRedesign&lt;/strong&gt; references the state of the logoRedesign branch on the remote named upstream (a common remote name)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;git branch -r&lt;/code&gt; to view the remote branches our local repository knows about.&lt;/li&gt;
&lt;li&gt;After committing, the master branch will move but the &lt;em&gt;remote tracking branch&lt;/em&gt; will remain unchanged&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;When you run &lt;code&gt;git status&lt;/code&gt; , it will show that the &lt;em&gt;master&lt;/em&gt; branch is ahead of ‘origin/master’ by 1 commit. To sync the remote branch with the local branch ,run &lt;code&gt;git push&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;git status
On branch master
Your branch is ahead of &lt;span class="s1"&gt;'origin/master'&lt;/span&gt; by 1 commit.
&lt;span class="o"&gt;(&lt;/span&gt;use &lt;span class="s2"&gt;"git push"&lt;/span&gt; to publish your &lt;span class="nb"&gt;local &lt;/span&gt;commits&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vZECg7Oq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zs7h4vb3da0s753b9y05.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vZECg7Oq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zs7h4vb3da0s753b9y05.png" alt="Image" width="677" height="314"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To go back to the original cloned state, run &lt;code&gt;git checkout origin/master&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Remote Branches
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Once you've cloned a repository, we have all the data and Git history for the project at that moment in time. However, that does not mean it's all in our workspace!&lt;/li&gt;
&lt;li&gt;The github repo has a branch called puppies, but when I run &lt;code&gt;git branch&lt;/code&gt; I don't see it on my machine! All I see is the master branch. So what's going on?&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;git branch -r&lt;/code&gt; to view the remote branches our local repository knows about.&lt;/li&gt;
&lt;li&gt;By default, my master branch is already tracking origin/master but there are no branches to track other remote branches. I want my own local branch called &lt;strong&gt;puppies&lt;/strong&gt;, and I want it to be connected to &lt;strong&gt;origin/puppies&lt;/strong&gt;, just like my local &lt;strong&gt;master&lt;/strong&gt; branch is connected to &lt;strong&gt;origin/master&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;git switch &amp;lt;remote-branch-name&amp;gt;&lt;/code&gt; to create a new local branch from the remote branch of the same name and connect it to the remote branch. For example, &lt;code&gt;git switch puppies&lt;/code&gt; makes me a local puppies branch AND sets it up to track the remote branch origin/puppies.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--i_Uown-3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7o1ybrhlx71zp1c1v21v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--i_Uown-3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7o1ybrhlx71zp1c1v21v.png" alt="Image" width="730" height="225"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Git Fetch
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Suppose that while you are working on the Local repository, the Github Repo has changed. How would you get those changes?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rivY6vY5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1upid6cqy3pwpyb23gam.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rivY6vY5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1upid6cqy3pwpyb23gam.png" alt="Image" width="745" height="350"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fetching allows us to download changes from a remote repository, BUT those changes will not be automatically integrated into our working files.&lt;/li&gt;
&lt;li&gt;It lets you see what others have been working on, without having to merge those changes into your local repo.&lt;/li&gt;
&lt;li&gt;Think of it as "Please go and get the latest information from Github, but don't screw up my working directory."&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;git fetch &amp;lt;remote&amp;gt;&lt;/code&gt; command fetches branches and history from a specific remote repository. It only updates remote tracking branches. For example, &lt;code&gt;git fetch origin&lt;/code&gt; would fetch all changes from the origin remote repository.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We can also fetch a specific branch from a remote using &lt;code&gt;git fetch &amp;lt;remote&amp;gt; &amp;lt;branch&amp;gt;&lt;/code&gt;. For example, &lt;code&gt;git fetch origin master&lt;/code&gt; would retrieve the latest information from the master branch on the origin remote repository.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git fetch &amp;lt;remote&amp;gt;
&lt;span class="c"&gt;# If not specified, &amp;lt;remote&amp;gt; defaults to origin&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LuK-NZea--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tztk98600jyppxginx2t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LuK-NZea--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tztk98600jyppxginx2t.png" alt="Image" width="631" height="357"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I now have those changes on my machine, but if I want to see them I have to &lt;strong&gt;checkout origin/master&lt;/strong&gt;. My master branch is untouched!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Git Pull
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git pull&lt;/code&gt; is another command we can use to retrieve changes from a remote repository. Unlike fetch, pull actually updates our HEAD branch with whatever changes are retrieved from the remote.&lt;/li&gt;
&lt;li&gt;"go and download data from Github AND immediately update my local repo with those changes"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yT0K3USf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1tw0f0csaxejrwyxewxp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yT0K3USf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1tw0f0csaxejrwyxewxp.png" alt="Image" width="734" height="127"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To pull, we specify the particular remote and branch we want to pull using &lt;code&gt;git pull &amp;lt;remote&amp;gt; &amp;lt;branch&amp;gt;&lt;/code&gt;. Just like with git merge, &lt;strong&gt;it matters WHERE we run this command from&lt;/strong&gt;. Whatever branch we run it from is where the changes will be merged into.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git pull origin master&lt;/code&gt; would fetch the latest information from the origin's master branch and merge those changes into our current branch.&lt;/li&gt;
&lt;li&gt;If we run &lt;code&gt;git pull&lt;/code&gt; without specifying a particular remote or branch to pull from, git assumes the following:

&lt;ul&gt;
&lt;li&gt;remote will default to origin&lt;/li&gt;
&lt;li&gt;branch will default to whatever tracking connection is configured for your current branch which is already setup.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;For example, if I am on my local master branch, then &lt;code&gt;git pull&lt;/code&gt; would pull from origin/master automatically.&lt;/li&gt;
&lt;li&gt;Pulls can result in conflicts hence we should always &lt;strong&gt;pull&lt;/strong&gt; first, then &lt;strong&gt;merge conflicts&lt;/strong&gt; and then &lt;strong&gt;push&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Git Fetch&lt;/th&gt;
&lt;th&gt;Git Pull&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Gets changes from remote branch(es)&lt;/td&gt;
&lt;td&gt;Gets changes from remote branch(es)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Updates the remote-tracking branches with the new changes&lt;/td&gt;
&lt;td&gt;Updates the current branch with the new changes, merging them in&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Does not merge changes onto your current HEAD branch&lt;/td&gt;
&lt;td&gt;Can result in merge conflicts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Safe to do at anytime&lt;/td&gt;
&lt;td&gt;Not recommended if you have uncommitted changes!&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4Yc-LpYp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t4w3dcaa1lvyossffcg1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4Yc-LpYp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t4w3dcaa1lvyossffcg1.png" alt="Image" width="778" height="442"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Undoing Changes and Time Travelling in Git</title>
      <dc:creator>Mustafa Hashmani</dc:creator>
      <pubDate>Fri, 18 Aug 2023 13:39:07 +0000</pubDate>
      <link>https://dev.to/mustafahashmani/undoing-changes-and-time-travelling-2fd1</link>
      <guid>https://dev.to/mustafahashmani/undoing-changes-and-time-travelling-2fd1</guid>
      <description>&lt;h2&gt;
  
  
  Checkout
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;git checkout&lt;/code&gt; command is like a Git Swiss Army knife. Many developers think it is overloaded, which is what lead to the addition of the &lt;code&gt;git switch&lt;/code&gt; and &lt;code&gt;git restore&lt;/code&gt; commands&lt;/li&gt;
&lt;li&gt;We can use checkout to create branches, switch to new branches, restore files, and undo history!&lt;/li&gt;
&lt;li&gt;We can use &lt;code&gt;git checkout &amp;lt;commit-hash&amp;gt;&lt;/code&gt; to view a previous commit. We just need the first 7 digits of a commit hash which can be obtained through &lt;code&gt;git log --oneline&lt;/code&gt;. Doing so will result in a &lt;em&gt;Detached Head.&lt;/em&gt; Now the &lt;code&gt;git log&lt;/code&gt; will change because we have moved back in time&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;git checkout&lt;/code&gt; supports a slightly odd syntax for referencing previous commits relative to a particular commit.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HEAD~1 refers to the commit before HEAD (parent)&lt;/li&gt;
&lt;li&gt;HEAD~2 refers to 2 commits before HEAD (grandparent
&lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;git checkout HEAD~1
&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_ECOUUsY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/repqqvnlxnt6vql6cj4z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_ECOUUsY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/repqqvnlxnt6vql6cj4z.png" alt="Image" width="713" height="233"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Discarding Changes
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Suppose you've made some changes to a file but don't want to keep them. To revert the file back to whatever it looked like when you last committed, you can use:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git checkout HEAD &amp;lt;filename&amp;gt;&lt;/code&gt; to discard any changes in that file, reverting back to the HEAD.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Restore
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git restore&lt;/code&gt; is a brand new Git command that helps with undoing operations. &lt;code&gt;git restore&lt;/code&gt; was introduced alongside &lt;code&gt;git switch&lt;/code&gt; as an alternative to some of the uses for &lt;code&gt;checkout&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Suppose you've made some changes to a file since your last commit. You've saved the file but then realize you definitely do NOT want those changes anymore!&lt;/li&gt;
&lt;li&gt;To restore the file to the contents in the HEAD, use &lt;code&gt;git restore &amp;lt;file-name&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git restore &amp;lt;file-name&amp;gt;&lt;/code&gt; restores using HEAD as the default source, but we can change that using the &lt;strong&gt;--source&lt;/strong&gt; option.&lt;/li&gt;
&lt;li&gt;For example, &lt;code&gt;git restore --source HEAD~1 home.html&lt;/code&gt; will restore the contents of home.html to its state from the commit prior to HEAD. You can also use a particular commit hash as the source.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;git status&lt;/code&gt; will always remind you what to use!&lt;/p&gt;
&lt;h3&gt;
  
  
  Unstaging Files with Restore
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;If you have accidentally added a file to your staging area with git add and you don't wish to include it in the next commit, you can use &lt;code&gt;git restore&lt;/code&gt; to remove it from staging.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use the --staged option like this:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git restore &lt;span class="nt"&gt;--staged&lt;/span&gt; &amp;lt;file-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Git Reset
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Suppose you've just made a couple of commits on the master branch, but you actually meant to make them on a separate branch instead. To undo those commits, you can use &lt;code&gt;git reset&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git reset &amp;lt;commit-hash&amp;gt;&lt;/code&gt; will reset the repo back to a specific commit. The commits are gone but the changes will be kept in the working directory.&lt;/li&gt;
&lt;li&gt;If you want to undo both the commits AND the actual changes in your files, you can use the &lt;strong&gt;--hard&lt;/strong&gt; option.&lt;/li&gt;
&lt;li&gt;For example, &lt;code&gt;git reset --hard HEAD~1&lt;/code&gt; will delete the last commit and associated changes.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Git Revert
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git revert&lt;/code&gt; is similar to git reset in that they both "undo" changes, but they accomplish it in different ways.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git reset&lt;/code&gt; actually moves the branch pointer backwards, eliminating commits.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git revert&lt;/code&gt; instead creates a brand new commit which reverses/undos the changes from a commit. Because it results in a new commit, you will be prompted to enter a commit message.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The history of the commit is preserved but the changes are reverted&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git revert &amp;lt;commit-hash&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yowrDN9m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d1gdoqpli0oq4kunxkyq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yowrDN9m--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d1gdoqpli0oq4kunxkyq.png" alt="Image" width="508" height="397"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fHX8Vht4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cefbgl0llcpkkiau71g1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fHX8Vht4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cefbgl0llcpkkiau71g1.png" alt="Image" width="750" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Which Command To Use?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Both &lt;code&gt;git reset&lt;/code&gt; and &lt;code&gt;git revert&lt;/code&gt; help us reverse changes, but there is a significant difference when it comes to collaboration.&lt;/li&gt;
&lt;li&gt;If you want to reverse some commits that other people already have on their machines, you should use &lt;strong&gt;revert&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;If you want to reverse commits that you haven't shared with others, use &lt;strong&gt;reset&lt;/strong&gt; and no one will ever know!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Theory of Git Checkout
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Usually, HEAD points to a specific branch reference rather than a particular commit. The HEAD is a pointer to the current branch reference and the branch reference is a pointer to the last commit made on a particular branch&lt;/li&gt;
&lt;li&gt;When we make a new commit, the branch reference is updated to reflect the new commit. The HEAD remains the same, because it's pointing at the branch reference. When you switch branches, HEAD is updated to point to the specific branch reference. This is all to say that HEAD usually refers to a branch NOT a specific commit.&lt;/li&gt;
&lt;li&gt;When we checkout a particular commit git checkout &lt;code&gt;git checkout d8194d6&lt;/code&gt;, HEAD points at that commit rather than at the branch pointer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZNBv4x_v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/itbp2y08s15wmucdi9e7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZNBv4x_v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/itbp2y08s15wmucdi9e7.png" alt="Image" width="587" height="238"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Detached Head
&lt;/h3&gt;

&lt;p&gt;You have a couple of options:&lt;br&gt;
    1. Stay in detached HEAD to examine the contents of the old &lt;br&gt;
       commit. Poke around, view the files, etc.&lt;br&gt;
    2. Leave and go back to wherever you were before - reattach &lt;br&gt;
       the HEAD&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 master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create a new branch after checking out the old commit and switch to it. You can now make and save changes since HEAD is no longer detached.

&lt;ol&gt;
&lt;li&gt;Suppose you want to go back to an old commit and make some
new changes&lt;/li&gt;
&lt;li&gt;Checkout the old commit. Now in detached HEAD state.&lt;/li&gt;
&lt;li&gt;While in detached HEAD, Make a new branch and switch to it. Head is now back to pointing at a branch reference!&lt;/li&gt;
&lt;li&gt;Now on the new branch, make as many new commits as you want! It's like you time traveled! We went back to an            old commit and made a new branch based on it.
&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;        git checkout &amp;lt;d8194d6&amp;gt;
        git switch &lt;span class="nt"&gt;-c&lt;/span&gt; newbranch
        git add &lt;span class="nb"&gt;.&lt;/span&gt;
        git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"new commit"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>github</category>
      <category>git</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Comparing Changes with Git Diff</title>
      <dc:creator>Mustafa Hashmani</dc:creator>
      <pubDate>Wed, 16 Aug 2023 03:21:43 +0000</pubDate>
      <link>https://dev.to/mustafahashmani/comparing-changes-with-git-diff-1634</link>
      <guid>https://dev.to/mustafahashmani/comparing-changes-with-git-diff-1634</guid>
      <description>&lt;h2&gt;
  
  
  Git Diff
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;We can use the &lt;code&gt;git diff&lt;/code&gt; command to view changes between commits, branches, files, our working directory, and more!&lt;/li&gt;
&lt;li&gt;We often use git diff alongside commands like git status and git log, to get a better picture of a repository and how it has changed over time.&lt;/li&gt;
&lt;li&gt;Without additional options, &lt;code&gt;git diff&lt;/code&gt; lists all the changes in our working directory that are NOT staged for the next commit.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git diff --staged&lt;/code&gt; will list the changes between the staging area and our last commit. You can think of it as "Show me what will be included in my commit if I run git commit right now"&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git diff HEAD&lt;/code&gt; lists all changes in the working tree since your last commit. It compares the HEAD and the working directory and shows both staged and unstaged changes.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git diff branch1..branch2&lt;/code&gt; will list the changes between the tips of branch1 and branch2. The order matters as the first branch is referred to as File A and second as File B.&lt;/li&gt;
&lt;li&gt;To compare two commits, provide git diff with the commit hashes of the commits in question in the form of &lt;code&gt;git diff commit1..commit2&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We can also view the changes within a specific file by providing git diff with a filename.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git diff HEAD &lt;span class="o"&gt;[&lt;/span&gt;filename]
git diff &lt;span class="nt"&gt;--staged&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;filename]
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Reading Git Diffs
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;For each comparison, Git explains which files it is comparing. Usually this is two versions of the same file.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Git also declares one file as "A"(&lt;strong&gt;old&lt;/strong&gt;) and the other as "B"(&lt;strong&gt;new&lt;/strong&gt;).&lt;/p&gt;
&lt;h3&gt;
  
  
  Markers
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;File A and File B are each assigned a symbol.

&lt;ul&gt;
&lt;li&gt;Changes in File A are indicated with a minus sign (-)&lt;/li&gt;
&lt;li&gt;Changes in File B are indicated with a plus sign (+)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Chunks
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;A diff won't show the entire contents of a file, but instead only shows portions or "chunks" that were modified.&lt;/li&gt;
&lt;li&gt;A chunk also includes some unchanged lines before and after a change to provide some context&lt;/li&gt;
&lt;li&gt;Each chunk starts with a chunk header, found between @@ and @@.&lt;/li&gt;
&lt;li&gt;There are two sets of numbers in the chunk. One set belongs to File A and the other belongs to File B, that is what the sign indicates&lt;/li&gt;
&lt;li&gt;The number with the sign indicates from which line no, the lines are extracted from and the second number indicates how many lines have been extracted.&lt;/li&gt;
&lt;li&gt;From file a, 4 lines are extracted starting from line 3.&lt;/li&gt;
&lt;li&gt;From file b, 5 lines are extracted starting from line 3&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nCEK1C8V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ynmfd4e3fjtoh14w6fv9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nCEK1C8V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ynmfd4e3fjtoh14w6fv9.png" alt="image" width="556" height="398"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Changes
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Every line that changed between the two files is marked with either a + or - symbol and lines without any sign exist in both files&lt;/li&gt;
&lt;li&gt;    Simply the - can be interpreted as removed and + as added.&lt;/li&gt;
&lt;li&gt;    lines that begin with - come from file A&lt;/li&gt;
&lt;li&gt;    lines that begin with + come from file B
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;    diff &lt;span class="nt"&gt;--git&lt;/span&gt; a/rainbow.txt b/rainbow.txt
    index 72d1d5a..f2c8117 100644
    &lt;span class="nt"&gt;---&lt;/span&gt; a/rainbow.txt
    +++ b/rainbow.txt
    @@ &lt;span class="nt"&gt;-3&lt;/span&gt;,4 +3,5 @@ orange
    yellow
    green
    blue
    &lt;span class="nt"&gt;-purple&lt;/span&gt;
    +indigo
    +violet

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>github</category>
      <category>git</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>An Introduction to Stashing in Git</title>
      <dc:creator>Mustafa Hashmani</dc:creator>
      <pubDate>Tue, 15 Aug 2023 07:16:01 +0000</pubDate>
      <link>https://dev.to/mustafahashmani/an-introduction-to-stashing-in-git-1a23</link>
      <guid>https://dev.to/mustafahashmani/an-introduction-to-stashing-in-git-1a23</guid>
      <description>&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Imagine a Scenario where you are on the master branch and you make a new branch and switch to it&lt;/li&gt;
&lt;li&gt;You do some new work but don’t make any commits. What happens when you switch back to master?

&lt;ol&gt;
&lt;li&gt;My changes come with me to the destination branch&lt;/li&gt;
&lt;li&gt;Git won't let me switch if it detects potential conflicts so it advises us to either commit or &lt;strong&gt;stash&lt;/strong&gt; them&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Stashing
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Git provides an easy way of stashing these uncommitted changes so that we can return to them later, without having to make unnecessary commits.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git stash&lt;/code&gt; is super useful command that helps you save changes that you are not yet ready to commit. You can stash changes and then come back to them later. Now that you have stashed my changes, you can switch branches, create new commits, etc.&lt;/li&gt;
&lt;li&gt;Running git stash will take all uncommitted changes (staged and unstaged) and stash them, reverting the changes in your working copy. We don’t see the changes but they are saved.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;git stash pop&lt;/code&gt; to remove the most recently stashed changes in your stash and re-apply them to your working copy.&lt;/li&gt;
&lt;li&gt;You can use &lt;code&gt;git stash apply&lt;/code&gt; to apply whatever is stashed away, without removing it from the stash. This can be useful if you want to apply stashed changes to multiple branches&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Stashing Multiple Times
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;You can add multiple stashes onto the stack of stashes. They will all be stashed in the order you added them.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;git stash list&lt;/code&gt; to view all stashes&lt;/li&gt;
&lt;li&gt;Git assumes you want to apply the most recent stash when you run &lt;code&gt;git stash apply&lt;/code&gt;, but you can also specify a particular stash like &lt;code&gt;git stash apply &amp;lt;stash-id&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;To delete a particular stash, you can use &lt;code&gt;git stash drop &amp;lt;stash-id&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;To clear out all stashes, run &lt;code&gt;git stash clear&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>A Guide to Working with Branches and Merging Branches</title>
      <dc:creator>Mustafa Hashmani</dc:creator>
      <pubDate>Tue, 15 Aug 2023 07:11:10 +0000</pubDate>
      <link>https://dev.to/mustafahashmani/a-guide-to-working-with-branches-and-merging-branches-90a</link>
      <guid>https://dev.to/mustafahashmani/a-guide-to-working-with-branches-and-merging-branches-90a</guid>
      <description>&lt;h2&gt;
  
  
  Context
&lt;/h2&gt;

&lt;p&gt;On large projects, we often work in multiple contexts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You're working on 2 different color scheme variations for your website at the same time, unsure of which you like best&lt;/li&gt;
&lt;li&gt;You're also trying to fix a horrible bug, but it's proving tough to solve. You need to really hunt around and toggle some code on and off to figure it out.&lt;/li&gt;
&lt;li&gt;A teammate is also working on adding a new chat widget to present at the next meeting. It's unclear if your company will end up using it.&lt;/li&gt;
&lt;li&gt;Another coworker is updating the search bar autocomplete.&lt;/li&gt;
&lt;li&gt;Another developer is doing an experimental radical design overhaul of the entire layout to present next month.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If they all work in a linear fashion(one commit after the next) this would be impossible and break other people’s code&lt;/p&gt;

&lt;h2&gt;
  
  
  Branches
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Branches are an essential part of Git!&lt;/li&gt;
&lt;li&gt;Think of branches as alternative timelines for a project.&lt;/li&gt;
&lt;li&gt;They enable us to create separate contexts where we can try new things, or even work on multiple ideas in parallel.&lt;/li&gt;
&lt;li&gt;If we make changes on one branch(files,folders,code), they do not impact the other branches (unless we merge the changes)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--H48pCru9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k81wxghpeg0j582h8z7s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--H48pCru9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k81wxghpeg0j582h8z7s.png" alt="Image description" width="716" height="314"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The Master Branch
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;In git, we are always working on a branch. The default branch name is &lt;strong&gt;master&lt;/strong&gt; when we are working on a new git repository.&lt;/li&gt;
&lt;li&gt;It doesn't do anything special or have fancy powers. It's just like any other branch.&lt;/li&gt;
&lt;li&gt;Many people designate the master branch as their "source of truth" or the "official branch" for their codebase, but that is left to you to decide.&lt;/li&gt;
&lt;li&gt;From Git's perspective, the master branch is just like any other branch. It does not have to hold the "master copy" of your project.&lt;/li&gt;
&lt;li&gt;In 2020, Github renamed the default branch from &lt;strong&gt;master&lt;/strong&gt; to &lt;strong&gt;main&lt;/strong&gt;. The default Git branch name is still master, though the Git team is exploring a potential change.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Head
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;We'll often come across the term &lt;strong&gt;HEAD&lt;/strong&gt; in Git.&lt;/li&gt;
&lt;li&gt;HEAD is simply a pointer that refers to the current "location" in your repository. It points to a particular branch reference.&lt;/li&gt;
&lt;li&gt;So far, HEAD always points to the latest commit you made on the master branch, but soon we'll see that we can move around and HEAD will change!&lt;/li&gt;
&lt;li&gt;The most recent commit on our master branch is always referred to as &lt;strong&gt;head → master&lt;/strong&gt; which means that the HEAD is pointing to the master branch&lt;/li&gt;
&lt;li&gt;Each branch has a branch pointer and the HEAD is a pointer to a branch pointer which points to where the branch currently is.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Viewing Branches
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;git branch&lt;/code&gt; to view your existing branches. The default branch in every git repo is master, though you can configure this.&lt;/li&gt;
&lt;li&gt;You can also use &lt;strong&gt;-v&lt;/strong&gt; option to view branches with last commits&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Look for the * which indicates the branch you are currently on.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch
git branch &lt;span class="nt"&gt;-v&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Creating and Switching Branches
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;git branch &amp;lt;branch-name&amp;gt;&lt;/code&gt; to make a new branch based upon the current HEAD so where you make the branch, matters&lt;/li&gt;
&lt;li&gt;The branch name should not include spaces, separated by a colon and should be informative&lt;/li&gt;
&lt;li&gt;This just creates the branch. It does not switch you to that branch (the HEAD stays the same)&lt;/li&gt;
&lt;li&gt;You should always add and commit changes before switching branches&lt;/li&gt;
&lt;li&gt;Once you have created a new branch, use &lt;code&gt;git switch &amp;lt;branch-name&amp;gt;&lt;/code&gt; to switch to it. If you have unstaged changes, they may come with you or git may abort the change&lt;/li&gt;
&lt;li&gt;Then HEAD will point to the &lt;strong&gt;&lt;/strong&gt; and the &lt;strong&gt;master&lt;/strong&gt; branch will be left behind&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We can also use &lt;code&gt;git switch&lt;/code&gt; with the &lt;strong&gt;-c&lt;/strong&gt; flag to create a new branch AND switch to it all in one go. Remember &lt;strong&gt;-c&lt;/strong&gt; as short for "create"&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch &amp;lt;branch-name&amp;gt;
git switch &amp;lt;branch-name&amp;gt;
git switch &lt;span class="nt"&gt;-c&lt;/span&gt; &amp;lt;branch-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Historically, we used &lt;code&gt;git checkout &amp;lt;branch-name&amp;gt;&lt;/code&gt; to switch branches. This still works.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The checkout command does a million additional things, so the decision was made to add a standalone switch command which is much simpler&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Deleting and Renaming Branches
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;You can use the &lt;strong&gt;-d&lt;/strong&gt; option with git branch to delete a branch. You cannot delete a branch you are currently on.&lt;/li&gt;
&lt;li&gt;To forcefully delete a branch use the &lt;strong&gt;-D&lt;/strong&gt; option&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You can rename a branch using the &lt;strong&gt;-m&lt;/strong&gt; option and you have to be on the branch that you want to rename.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git branch &lt;span class="nt"&gt;-d&lt;/span&gt; deleteMe
git branch &lt;span class="nt"&gt;-D&lt;/span&gt; deleteMe
git branch &lt;span class="nt"&gt;-m&lt;/span&gt; deleteIt

&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Merging Branches
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Branching makes it super easy to work within self-contained contexts, but often we want to incorporate changes from one branch into another!&lt;/li&gt;
&lt;li&gt;We treat the &lt;strong&gt;master&lt;/strong&gt; branch as the most stable build of an application where you don’t want to screw anything up so people work on a feature branch and then that work is incorporated back into the master branch if it is useful&lt;/li&gt;
&lt;li&gt;We can do this using the &lt;code&gt;git merge&lt;/code&gt; command&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;We merge branches, not specific commits&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;We always merge to the current HEAD branch&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Both branches will still remain separate after merging&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To merge, follow these basic steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Switch to or checkout the branch you want to merge the changes into (the receiving branch)&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use the &lt;code&gt;git merge&lt;/code&gt; command to merge changes from a specific branch into the current branch.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git switch master
git merge bugfix
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;This Is Called A &lt;strong&gt;Fast-Forward.&lt;/strong&gt; The &lt;strong&gt;Master&lt;/strong&gt; branch simply caught up/fast-forwarded on the commits from Bugfix&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Not All Merges Are Fast Forwards! What if we add a commit on master?&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rS9yX4pG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ij3hbh2zibphvix29oew.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rS9yX4pG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ij3hbh2zibphvix29oew.png" alt="Image description" width="624" height="301"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rather than performing a simple fast forward, git performs a "merge commit" We end up with a new commit on the master branch. Git will prompt you for a message. The new commit will have two parents&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fF1qMsal--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9h3txmdqy57z2a5qubsw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fF1qMsal--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9h3txmdqy57z2a5qubsw.png" alt="Image description" width="752" height="305"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Resolving Merge Conflicts
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Depending on the specific changes you are trying to merge, Git may not be able to automatically merge.&lt;/li&gt;
&lt;li&gt;This results in &lt;strong&gt;merge conflicts&lt;/strong&gt;, which you need to manually resolve.&lt;/li&gt;
&lt;li&gt;When you encounter a merge conflict, Git warns you in the console that it could not automatically merge.&lt;/li&gt;
&lt;li&gt;The content from your current &lt;strong&gt;HEAD&lt;/strong&gt; (the branch you are trying to merge content into) is displayed &lt;strong&gt;between the &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt; HEAD and =======&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The content from the branch you are trying to merge from is displayed &lt;strong&gt;between the ======= and &amp;gt;&amp;gt;&amp;gt;&amp;gt; symbols&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&lt;/span&gt;&amp;lt; HEAD
I have 2 cats
I also have chickens
&lt;span class="o"&gt;=======&lt;/span&gt;
I used to have a dog :&lt;span class="o"&gt;(&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; bug-fix
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Whenever you encounter merge conflicts, follow these steps to resolve them:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open up the file(s) with merge conflicts&lt;/li&gt;
&lt;li&gt;Edit the file(s) to remove the conflicts. Decide which branch's content you want to keep in each conflict. Or keep the content from both.&lt;/li&gt;
&lt;li&gt;Remove the conflict "markers" in the document&lt;/li&gt;
&lt;li&gt;Add your changes and then make a commit using the message “resolve conflicts”!&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Or you can use VSCode to resolve the conflicts&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Basics of Git: Adding and Committing</title>
      <dc:creator>Mustafa Hashmani</dc:creator>
      <pubDate>Mon, 14 Aug 2023 20:18:18 +0000</pubDate>
      <link>https://dev.to/mustafahashmani/basics-of-git-adding-and-committing-3p96</link>
      <guid>https://dev.to/mustafahashmani/basics-of-git-adding-and-committing-3p96</guid>
      <description>&lt;h2&gt;
  
  
  Repository
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A Git "Repo" is a workspace which tracks and manages files within a folder.&lt;/li&gt;
&lt;li&gt;Anytime we want to use Git with a project, app, etc we need to create a new git repository.&lt;/li&gt;
&lt;li&gt;We can have as many repos on our machine as needed, all with separate histories and contents&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git status&lt;/code&gt; gives information on the current status of a git repository and its contents&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;git init&lt;/code&gt; to create a new git repository. Before we can do anything git-related, we must initialize a repo first!&lt;/li&gt;
&lt;li&gt;Before running &lt;code&gt;git init&lt;/code&gt;, use &lt;code&gt;git status&lt;/code&gt; to verify that you are not currently inside of a repo.&lt;/li&gt;
&lt;li&gt;This is something you do once per project. Initialize the repo in the top level folder containing your project&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;🚨 Do not INIT a repo inside of a repo&lt;/p&gt;

&lt;h2&gt;
  
  
  The Basic Git Workflow
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Make new files, edit files, delete files, etc

&lt;ol&gt;
&lt;li&gt;Then run &lt;code&gt;git status&lt;/code&gt; which will tell you the untracked and modified files&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;li&gt;Group specific changes together, in preparation of committing(&lt;strong&gt;git add&lt;/strong&gt;)&lt;/li&gt;
&lt;li&gt;Commit everything that was previously added(&lt;strong&gt;git commit&lt;/strong&gt;)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EhYJWmzB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s7wvhjqw0s91vdm64585.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EhYJWmzB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s7wvhjqw0s91vdm64585.png" alt="Image description" width="545" height="466"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;We use the &lt;code&gt;git add&lt;/code&gt; command to stage changes to be committed.&lt;/li&gt;
&lt;li&gt;It's a way of telling Git, "please include this change in our next commit"&lt;/li&gt;
&lt;li&gt;Use git add to add specific files to the staging area. Separate files with spaces to add multiple at once.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;git add .&lt;/code&gt; to stage all changes at once rather than typing the filenames&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;After adding &lt;code&gt;git status&lt;/code&gt; , will show that the changes in the file are ready to be committed&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add file1 file2
git add &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Committing
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Making a commit is similar to making a save in a video game. We're taking a snapshot of a git repository in time and marking a checkpoint.&lt;/li&gt;
&lt;li&gt;When saving a file, we are saving the state of a single file. With Git, we can save the state of multiple files and folders together.&lt;/li&gt;
&lt;li&gt;We have to make changes first and then save them to our files before we can commit. Once we have made changes and added them, we can group them together into a commit.&lt;/li&gt;
&lt;li&gt;We use the &lt;code&gt;git commit&lt;/code&gt; command to actually commit changes from the staging area.&lt;/li&gt;
&lt;li&gt;When making a commit, we need to provide a commit message that summarizes the changes and work snapshotted in the commit&lt;/li&gt;
&lt;li&gt;Running &lt;code&gt;git commit&lt;/code&gt; will commit all staged changes. It also opens up a text editor and prompts you for a commit message. You can also use the &lt;strong&gt;-m&lt;/strong&gt; flag which allows us to pass in an inline commit message, rather than launching a text editor.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git log --oneline&lt;/code&gt; gives a summary for the log of the commits for a given repository&lt;/li&gt;
&lt;li&gt;You can also pass &lt;strong&gt;-a&lt;/strong&gt; option to git commit which will add and commit altogether.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use &lt;code&gt;git config --global core.editor "code --wait”&lt;/code&gt; to configure VSCode to pass the commit messages when you are not using &lt;strong&gt;-m&lt;/strong&gt; to pass longer messages&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"my message"&lt;/span&gt;
git commit &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"my message"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;
  
  
  Atomic Commits
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;When possible, a commit should encompass a single feature, change, or fix. In other words, try to &lt;strong&gt;keep each commit focused on a single thing.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;This makes it much easier to undo or rollback changes later on. It also makes your code or project easier to review.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Writing Commit Messages
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Describe your changes in imperative mood, e.g. "make xyzzy do frotz" instead of "[This patch] makes xyzzy do frotz" or "I changed xyzzy to do frotz", as if &lt;strong&gt;you are giving orders to the codebase to change its behavior.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Many developers prefer the past tense “added head”&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Amending Commits
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Suppose you just made a commit and then realized you forgot to include a file! Or, maybe you made a typo in the commit message that you want to correct.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Rather than making a brand new separate commit, you can "redo" the previous commit using the --amend option&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s1"&gt;'some commit'&lt;/span&gt;
git add forgotten_file
git commit &lt;span class="nt"&gt;--amend&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Ignoring Files
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;We can tell Git which files and directories to ignore in a given repository, using a &lt;strong&gt;.gitignore&lt;/strong&gt; file. This is useful for files you know you NEVER want to
commit, including:

&lt;ul&gt;
&lt;li&gt;Secrets, API keys, credentials, etc.&lt;/li&gt;
&lt;li&gt;Operating System files (.DS_Store on Mac)&lt;/li&gt;
&lt;li&gt;Log files&lt;/li&gt;
&lt;li&gt;Dependencies &amp;amp; packages&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;You will have the file locally but you don’t want git to track it&lt;/li&gt;
&lt;li&gt;Create a file called .gitignore in the root of a repository using &lt;code&gt;touch .gitignore&lt;/code&gt;. Inside the file, we can write patterns to tell Git which files &amp;amp; folders to ignore:

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;.DS_Store&lt;/code&gt; will ignore files named .DS_Store&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;folderName/&lt;/code&gt; will ignore an entire directory&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;*.log&lt;/code&gt; will ignore any files with the .log extension&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>A Guide to Permissions in Ubuntu</title>
      <dc:creator>Mustafa Hashmani</dc:creator>
      <pubDate>Wed, 09 Aug 2023 14:49:18 +0000</pubDate>
      <link>https://dev.to/mustafahashmani/a-guide-to-permissions-in-ubuntu-36o2</link>
      <guid>https://dev.to/mustafahashmani/a-guide-to-permissions-in-ubuntu-36o2</guid>
      <description>&lt;ul&gt;
&lt;li&gt;As regular users, we do not have permission to write or even read every file on the machine.&lt;/li&gt;
&lt;li&gt;For example, if I try to read the file /etc/sudoers using cat /etc/sudoers I get a "permission denied" message.&lt;/li&gt;
&lt;li&gt;On unix systems, a single user may be the owner of files and directories, meaning that they have control over their access.&lt;/li&gt;
&lt;li&gt;You can view permissions by running &lt;code&gt;ls -l&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  File Attributes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The weird looking 10 characters we see printed out first are the file attributes.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nt"&gt;-rw-rw-r--&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;These characters tell us the type of the file, the read, write, and execute permissions for the file's owner, the file's group owner, and everyone else.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--p3lMFjiq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/af372mh19xd09map6v4b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--p3lMFjiq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/af372mh19xd09map6v4b.png" alt="Image" width="673" height="209"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The very first character indicates the type of the file. Some of the more common types and their corresponding attributes are:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;-&lt;/strong&gt; regular file&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;d&lt;/strong&gt; directory&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;c&lt;/strong&gt; character special file&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;l&lt;/strong&gt; symbolic link&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Character&lt;/th&gt;
&lt;th&gt;Effect On Files&lt;/th&gt;
&lt;th&gt;Effect on Directories&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;r&lt;/td&gt;
&lt;td&gt;file can be read&lt;/td&gt;
&lt;td&gt;directory's contents can be listed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;w&lt;/td&gt;
&lt;td&gt;file can be modified&lt;/td&gt;
&lt;td&gt;directory's contents can be modified (create new files, rename files/folders) but only if the executable attribute is also set&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;x&lt;/td&gt;
&lt;td&gt;file can be treated as a program to be executed&lt;/td&gt;
&lt;td&gt;allows a directory to be entered or "cd"ed into&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;-&lt;/td&gt;
&lt;td&gt;file cannot be read, modified, or executed&lt;/td&gt;
&lt;td&gt;directory contents cannot be shown, modified, or cd'ed into&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;In the example below we see that the file's owner has read and write permissions but NOT execute permissions. No one else has any access&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;- rw- &lt;span class="nt"&gt;---&lt;/span&gt; &lt;span class="nt"&gt;---&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the example below, we see that the file's owner has read, write, AND execute permissions. No one else has any access&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;- rwx &lt;span class="nt"&gt;---&lt;/span&gt; &lt;span class="nt"&gt;---&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the example below, we see that the file's owner has read, and write BUT NOT execute permissions. Members of the file's owner group can only read the file and everyone else can read the file too.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;- rw- r-- r--
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the above example, we see that the directory's owner and member's of the owner group can enter the directory, rename, and remove files from within the directory&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;d rwx rwx &lt;span class="nt"&gt;---&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Altering Permissions
&lt;/h1&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;chmod&lt;/code&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;To change the permissions of a file or directory, we can use the chmod command (change mode).&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;chmod &lt;/span&gt;mode file
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To use chmod to alter permissions, we need to tell it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Who&lt;/strong&gt; we are changing permissions for&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;What&lt;/strong&gt; change are we making? Adding? Removing?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Which&lt;/strong&gt; permissions are we setting?&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When specifying permissions with chmod, we use a special syntax to write permission statements.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;First, we specify the "who" using the following values:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;u&lt;/strong&gt; - user (the owner of the file)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;g&lt;/strong&gt; - group (members of the group the file belongs to)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;o&lt;/strong&gt; - others (the "world")&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;a&lt;/strong&gt; - all of the above&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Next, we tell chmod "what" we are doing using the following characters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;- (minus sign) removes the permission&lt;/li&gt;
&lt;li&gt;+ (plus sign) grants the permission&lt;/li&gt;
&lt;li&gt;= (equals sign) set a permission and removes others&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;Finally, the "which" values are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;r&lt;/strong&gt; - the read permission&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;w&lt;/strong&gt; - the write permission&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;x&lt;/strong&gt; - the execute permission
&lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Before : - rw- r-- r--&lt;/span&gt;
&lt;span class="nb"&gt;chmod &lt;/span&gt;g+w file.txt
&lt;span class="c"&gt;# After : - rw- rw- r--&lt;/span&gt;

&lt;span class="c"&gt;# Before : - rw- rw- r--&lt;/span&gt;
&lt;span class="nb"&gt;chmod &lt;/span&gt;a-w file.txt
&lt;span class="c"&gt;# After : - r-- r-- r--&lt;/span&gt;

&lt;span class="c"&gt;# Before : - rwx rwx r--&lt;/span&gt;
&lt;span class="nb"&gt;chmod &lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;r file.txt
&lt;span class="c"&gt;# After : - r-- r-- r--&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;



&lt;h3&gt;
  
  
  chmod Octals
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;chmod also supports another way of representing permission patterns: octal numbers (base 8). Each digit in an octal number represents 3 binary digits.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UcdwMdMr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v6hx6i2q3m29bwyj7lu5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UcdwMdMr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v6hx6i2q3m29bwyj7lu5.png" alt="Image description" width="225" height="236"&gt;&lt;/a&gt;&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="nb"&gt;chmod &lt;/span&gt;755 file.txt &lt;span class="c"&gt;# rwx r-x r-x&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Root User
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;In Linux systems, there is a super user called root. The root user can run any command and access any file on the machine, regardless of the file's actual owner.&lt;/li&gt;
&lt;li&gt;The root user has tons of power and could easily damage or even destroy the system by running the wrong commands!&lt;/li&gt;
&lt;li&gt;For this reason, Ubuntu locks the root user by default.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;sudo&lt;/code&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Even if the root user is locked by default, we can still run specific commands as the root user by using the &lt;code&gt;sudo&lt;/code&gt; command.&lt;/li&gt;
&lt;li&gt;Individual users are granted an "allowed" list of commands they can run as the super user.&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;sudo -l&lt;/code&gt; to see the permitted commands for your particular user.&lt;/li&gt;
&lt;li&gt;To run a command as the root user, prefix it with sudo. You will then need to enter the password for your account.&lt;/li&gt;
&lt;li&gt;For example to update Ubuntu, I would need to run &lt;code&gt;apt update&lt;/code&gt;. However, I can't do this as my "regular" user, as it's something that impacts all users. Instead, I need to run the command as the root user using &lt;code&gt;sudo apt update&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;If you run into permissions denied, prefix the command with &lt;code&gt;sudo&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>linux</category>
      <category>terminal</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>A Guide to Searching through the Command Line</title>
      <dc:creator>Mustafa Hashmani</dc:creator>
      <pubDate>Wed, 09 Aug 2023 00:01:03 +0000</pubDate>
      <link>https://dev.to/mustafahashmani/a-guide-to-searching-through-the-command-line-4708</link>
      <guid>https://dev.to/mustafahashmani/a-guide-to-searching-through-the-command-line-4708</guid>
      <description>&lt;h2&gt;
  
  
  &lt;code&gt;locate&lt;/code&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;locate&lt;/code&gt; command performs a search of pathnames across our machine that match a given substring and then prints out any matching names.&lt;/li&gt;
&lt;li&gt;You have to install this command as it does not comes pre-installed&lt;/li&gt;
&lt;li&gt;It is nice and speedy because it uses a pre-generated database file rather than searching the entire machine.&lt;/li&gt;
&lt;li&gt;For example, &lt;code&gt;locate chick&lt;/code&gt; will perform a search for all files that contain chick in their name&lt;/li&gt;
&lt;li&gt;It does not matter which directory you are in as you can locate folders which are in other directories&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;-i&lt;/strong&gt; option tells locate to ignore casing&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;-l&lt;/strong&gt; or --limit option will limit the number of entries to a number.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;find&lt;/code&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The locate command is nice and easy, but it can only do so much! The &lt;strong&gt;find&lt;/strong&gt; command is far more powerful! Unlike locate, find does not use a database file.&lt;/li&gt;
&lt;li&gt;By default, &lt;code&gt;find&lt;/code&gt; on its own will list every single file and directory nested in our current working directory and also nested in the sub-directories.&lt;/li&gt;
&lt;li&gt;We can also provide a specific folder. &lt;code&gt;find friends/&lt;/code&gt; would print all the files and directories inside the friends directory (including nested folders)&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You can also find empty files by running &lt;code&gt;find -empty&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Finding by Type
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;We can tell find to only find by file type: only print files, directories, symbolic links, etc using the -type option.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;find -type f&lt;/code&gt; will limit the search to files&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;find -type d&lt;/code&gt; will limit the search to directories&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Finding by Name
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;We can provide a specific pattern for &lt;code&gt;find&lt;/code&gt; to use when matching filenames and directories with the &lt;strong&gt;-name&lt;/strong&gt; option. We need to enclose our pattern in quotes.&lt;/li&gt;
&lt;li&gt;To find all files on our Desktop that end in the .txt extension, we could run &lt;code&gt;find ~/Desktop -name "*.txt"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Use the -iname option for a case insensitive search&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Finding by Size
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;We can use the &lt;strong&gt;-size&lt;/strong&gt; option to find files of a specific size. For example, to find all files larger than 1 gigabyte we could run &lt;code&gt;find -size +1G&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;To find all files under 50 megabytes, we could run &lt;code&gt;find -size -50M&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;To find all files that are exactly 20 kilobytes, we could run &lt;code&gt;find -size 20k&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Finding by Time
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;mtime&lt;/strong&gt;, or modification time, is when a file was last modified AKA when its contents last changed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ctime&lt;/strong&gt;, or change time, is when a file was last changed. This occurs anytime mtime changes but also when we rename a file, move it, or alter permissions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;atime&lt;/strong&gt;, or access time, is updated when a file is read by an application or a command like cat.&lt;/li&gt;
&lt;li&gt;We can use the &lt;code&gt;-mtime num&lt;/code&gt; option to match files/folders that were last modified num*24 hours ago.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;find -mmin -20&lt;/code&gt; matches items that were modified LESS than 20 minutes ago.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;find -mmin +60&lt;/code&gt; matches items that were modified more than 60 minutes ago&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;find &lt;span class="nt"&gt;-mmin&lt;/span&gt; &lt;span class="nt"&gt;-30&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;find -amin n&lt;/code&gt; will find files that were last accessed n minutes ago. We can specify +n for "greater than n minutes ago" and -n for "less than n minutes ago"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;find -cmin -20&lt;/code&gt; matches items that were changed LESS than 20 minutes ago.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;find -cmin +60&lt;/code&gt; matches items that were changed more than 60 minutes ago&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Logical Operators
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;We can also use the &lt;strong&gt;-and&lt;/strong&gt;, &lt;strong&gt;-or&lt;/strong&gt;, and &lt;strong&gt;-not&lt;/strong&gt; operators to create more complex queries.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;find &lt;span class="nt"&gt;-type&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="nt"&gt;-not&lt;/span&gt; &lt;span class="nt"&gt;-name&lt;/span&gt; &lt;span class="s2"&gt;"*.html"&lt;/span&gt; &lt;span class="c"&gt;# any file except .html&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  User-Defined Actions
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;We can provide find with our own action to perform using each matching pathname.&lt;/li&gt;
&lt;li&gt;The syntax is &lt;code&gt;find -exec command {} ;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The {} are a placeholder for the current pathname (each match), and the semicolon is required to indicate the end of the command.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To delete every file that starts with contains "broken" in its file name, we could run:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;find &lt;span class="nt"&gt;-name&lt;/span&gt; &lt;span class="s2"&gt;"*broken*"&lt;/span&gt; &lt;span class="nt"&gt;-exec&lt;/span&gt; &lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="s1"&gt;'{}'&lt;/span&gt; &lt;span class="s1"&gt;';'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Note that we need to wrap the {} and ; in quotes because those characters have special meanings otherwise&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;xargs&lt;/code&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;When we provide a command via &lt;code&gt;-exec&lt;/code&gt;, that command is executed separately for every single element.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We can instead use a special command called &lt;code&gt;xargs&lt;/code&gt; to build up the input into a bundle that will be provided as an argument list to the next command.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;find &lt;span class="nt"&gt;-name&lt;/span&gt; &lt;span class="s2"&gt;"*.txt"&lt;/span&gt; &lt;span class="nt"&gt;-exec&lt;/span&gt; &lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="s1"&gt;'{}'&lt;/span&gt; &lt;span class="s1"&gt;';'&lt;/span&gt;
find &lt;span class="nt"&gt;-name&lt;/span&gt; &lt;span class="s2"&gt;"*.txt"&lt;/span&gt; | xargs &lt;span class="nb"&gt;ls&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;This example finds four individual chapter files (chapter1, chapter2, chapter3, and chapter4) and then passes them to the cat command, which then outputs the combined contents to a file called fullbook.txt.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;find &lt;span class="nt"&gt;-name&lt;/span&gt; &lt;span class="s2"&gt;"chapter[1-4].txt"&lt;/span&gt; | xargs &lt;span class="nb"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; fullbook.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;xargs reads items from standard input, separated by blanks (spaces or newlines) and then executes a command using those items&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The mkdir command expects us to pass arguments. It doesn't work with standard input, so this example does NOT make any folders for us&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We can instead add in the xargs command, which will accept the standard input coming from echo and pass them as arguments to mkdir.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"hello"&lt;/span&gt; &lt;span class="s2"&gt;"world"&lt;/span&gt; | &lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="c"&gt;# mkdir: missing operand&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"hello"&lt;/span&gt; &lt;span class="s2"&gt;"world"&lt;/span&gt; | xargs &lt;span class="nb"&gt;mkdir
ls&lt;/span&gt; &lt;span class="c"&gt;# hello world two folders made&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Grep
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;grep&lt;/code&gt; command searches for patterns in each file's contents. Grep will print each line that matches a pattern we provide.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For example, &lt;code&gt;grep "chicken" animals.txt&lt;/code&gt; will print each line from the animals.txt file that contains the pattern "chicken"&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;grep &lt;/span&gt;PATTERN FILE
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use the &lt;strong&gt;-i&lt;/strong&gt; option with grep to make the search case insensitive.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;grep -i "Chapter" book.txt&lt;/code&gt; will print all matching lines from the book.txt file that contain the word "chapter" in any casing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use the &lt;strong&gt;-w&lt;/strong&gt; option to ensure that grep only matches words, rather than fragments located inside of other words.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;grep -w "cat" book.txt&lt;/code&gt; would match cat but not catheter!&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use the &lt;strong&gt;-r&lt;/strong&gt; option to perform a recursive search which will include all files under a directory, subdirectories and their files, and so on.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;grep -r "chicken"&lt;/code&gt; will search the current working directory and any nested directories for lines that contain "chicken"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;strong&gt;-c&lt;/strong&gt; option tells grep to print the number of matches instead of printing the actual matches&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;strong&gt;-o&lt;/strong&gt; option tells grep to only print out the matches, rather than the entire line containing each match.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We can also provide regular expressions to grep by using the &lt;strong&gt;-E&lt;/strong&gt; option&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>beginners</category>
      <category>tutorial</category>
      <category>productivity</category>
      <category>learning</category>
    </item>
    <item>
      <title>Redirecting and Piping Command through the Command Line</title>
      <dc:creator>Mustafa Hashmani</dc:creator>
      <pubDate>Mon, 07 Aug 2023 18:43:04 +0000</pubDate>
      <link>https://dev.to/mustafahashmani/redirecting-and-piping-command-through-the-command-line-202p</link>
      <guid>https://dev.to/mustafahashmani/redirecting-and-piping-command-through-the-command-line-202p</guid>
      <description>&lt;h2&gt;
  
  
  Standard Streams
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The three standard streams are communication channels between a computer program and its environment.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;They are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Standard Input&lt;/li&gt;
&lt;li&gt;Standard Output&lt;/li&gt;
&lt;li&gt;Standard Error&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Standard Output
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Standard output is a place to which a program or command can send information.&lt;/li&gt;
&lt;li&gt;The information could go to a screen to be displayed, to a file, or even to a printer or other devices.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mN6uuK_8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/22vmmr84346ebx726dcc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mN6uuK_8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/22vmmr84346ebx726dcc.png" alt="photo" width="473" height="150"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Standard Error
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Commands and programs also have a destination to send error 
messages: standard error.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;By default, the shell directs standard error information to &lt;br&gt;
the screen for us to read, but we can change that &lt;br&gt;
destination if needed!&lt;/p&gt;
&lt;h2&gt;
  
  
  Standard Input
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Standard input is where a program or command gets its input information from. By default, the shell directs standard input from the keyboard.&lt;/li&gt;
&lt;li&gt;The input information could come from a keyboard, a file, or even from another command!&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iZbklxs0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/enr2wudbel8h3zbxuwro.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iZbklxs0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/enr2wudbel8h3zbxuwro.png" alt="Image description" width="698" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Redirection
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;"redirection" describes the ways we can alter the source of standard input, and the destinations for standard output and standard error.&lt;/p&gt;
&lt;h2&gt;
  
  
  Redirecting Output
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The redirect output symbol (&lt;strong&gt;&amp;gt;&lt;/strong&gt;) tells the shell to redirect the output of a command to a specific file instead of the screen.&lt;/li&gt;
&lt;li&gt;By default, the &lt;code&gt;date&lt;/code&gt; command will print the current date to the screen. If we instead run &lt;code&gt;date &amp;gt; output.txt&lt;/code&gt; the output will be redirected to a file called output.txt&lt;/li&gt;
&lt;li&gt;If the file does not exist, it will be automatically created.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: the &amp;gt; symbol needs to occur after any options and arguments!&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;command&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; filename
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"moo"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; cow.js &lt;span class="c"&gt;# redirects the output of echo&lt;/span&gt;
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; files.txt &lt;span class="c"&gt;# saves the output of ls -l to a file.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Appending
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;When we redirect output into a file using &lt;strong&gt;&amp;gt;&lt;/strong&gt; any existing contents in the file are overwritten. Sometimes this is not what we want!&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Instead, keep the existing contents in the file and add new content to the end of the file, use &lt;strong&gt;&amp;gt;&amp;gt;&lt;/strong&gt; when redirecting.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"hello"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; greeting.txt
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"world"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; greeting.txt
&lt;span class="nb"&gt;cat &lt;/span&gt;greeting.txt
&lt;span class="c"&gt;#hello&lt;/span&gt;
&lt;span class="c"&gt;#world&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Redirecting Input
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;To pass the contents of a file to standard input, use the &lt;strong&gt;&amp;lt;&lt;/strong&gt; symbol followed by the filename.&lt;/li&gt;
&lt;li&gt;For example, we could pass the contents of the chickens.txt file to the cat command using &lt;code&gt;cat &amp;lt; chickens.txt&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;cat (and many other commands) are set up to accept filenames as arguments directly, but we can also redirect to standard input manually.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;command&lt;/span&gt; &amp;lt; filename
&lt;span class="nb"&gt;cat&lt;/span&gt; &amp;lt; chickens.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We can redirect standard input and output at the same time! In this example, we are using cat to read in the contents of original.txt and then redirecting the output to a file called output.txt&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In this example, we are redirecting the names.txt file to the sort command. We are also redirecting the output of sort to a file called sorted.txt&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; &amp;lt; original.txt &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; output.txt
&lt;span class="nb"&gt;sort&lt;/span&gt; &amp;lt; names.txt &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; sorted.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Redirecting Standard Error
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;By default, error messages are output to the screen, but we can change this by redirecting standard error.&lt;/li&gt;
&lt;li&gt;The standard error redirection operator is &lt;code&gt;2&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;If we ran a command like &lt;code&gt;cat nonexistentfile&lt;/code&gt; (where the file does not exist) we would see an error printed to the screen. We can instead redirect standard error to a file with &lt;code&gt;cat nonexistentfile 2&amp;gt; error.txt&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can use the same &amp;gt;&amp;gt; syntax to append when redirecting standard 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="nb"&gt;cat &lt;/span&gt;nonexistentfile 2&amp;gt; error.txt
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-zzz&lt;/span&gt; 2&amp;gt;&amp;gt; error.txt &lt;span class="c"&gt;# ls with illegal option&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Why 2&amp;gt; ?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Each stream gets its own numeric file descriptor, and for standard error the number is 2.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &amp;gt; operator actually defaults to using 1 as the file descriptor number, which is why we didn't need to specify 1&amp;gt; to redirect standard output&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Similarly, the &amp;lt; operator uses a default file descriptor number of 0, so we don't need to specify 0&amp;lt; to redirect to standard input (though we can!)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ruHIqgie--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6lds9y2rkse6wvm6azfh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ruHIqgie--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6lds9y2rkse6wvm6azfh.png" alt="Image description" width="348" height="145"&gt;&lt;/a&gt;    &lt;/p&gt;

&lt;h2&gt;
  
  
  All Together now
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;We can redirect multiple streams at once! In this example, we are concatenating two files, redirecting standard output to a file called insects.txt, and redirecting standard error to a file called error.txt&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When redirecting both standard output and standard error, make sure standard output comes FIRST. Always redirect standard error after standard output.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cat &lt;/span&gt;bees.txt ants.txt &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; insects.txt 2&amp;gt; error.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--X7YjOBTU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ib79fx2oc6skqnx02w7t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--X7YjOBTU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ib79fx2oc6skqnx02w7t.png" alt="Image" width="547" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Pipes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Pipes are used to redirect a stream from one program to another program. We can take the output of one command and redirect it to the input of another.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We use the pipe character ( | ) to separate two commands. The output of the first command will be passed to the standard input of the second command.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;This example shows the output of the date command being piped to the rev command. The result is the reverse of the current date!&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;command1 | command2
&lt;span class="nb"&gt;date&lt;/span&gt; | rev
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Tx0uMHmV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n1ma41vdrqgqyg0dizlp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Tx0uMHmV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n1ma41vdrqgqyg0dizlp.png" alt="Image description" width="640" height="183"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;This example pipes the output of &lt;strong&gt;ls&lt;/strong&gt; to &lt;strong&gt;less&lt;/strong&gt;. The /usr/bin directory typically contains a bunch of stuff, so it can be nice to use less to read the results in a more manageable way.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; /usr/bin | less
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;This example counts the number of files (non hidden files) in a directory. We pipe the output of ls to the word count command. The -l option tells wc to count the number of lines.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; | &lt;span class="nb"&gt;wc&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nCPUs39L--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bz65qfupma47d0xyzni7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nCPUs39L--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bz65qfupma47d0xyzni7.png" alt="Image description" width="615" height="207"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;In this example, we are calling tac with a file and then piping the output to rev. The final result is the content of file.txt printed "horizontally" and "vertically" reversed&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;tac &lt;/span&gt;file.txt | rev
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ys6PhoKi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6is2paxpwqchvajjl74g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ys6PhoKi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6is2paxpwqchvajjl74g.png" alt="Image description" width="631" height="212"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;This example concatenates two files using cat and then sorts them alphabetically&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cat &lt;/span&gt;colors.txt pets.txt | &lt;span class="nb"&gt;sort&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &amp;amp;gt; vs |
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Though both the &amp;gt; character and the | character are used to redirect output, they do it in very different ways.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&amp;amp;gt;&lt;/strong&gt; connects a command to some file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;| connects a command to another command.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; /usr/bin &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; list.txt
&lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; /usr/bin | less
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;tee&lt;/code&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;What if I wanted to create a file with the output of cat? Enter the tee command&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The tee program reads standard input and copies it both to standard output AND to a file. This allows us to capture information part of the way through a pipeline, without interrupting the flow.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;It takes some informations coming from one command and gives it to a file we specify and also passes it to the next command. Hence this allows us to take information in the middle of a pipeline and save it to a file without stopping.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;command1 | &lt;span class="nb"&gt;tee &lt;/span&gt;file.txt | command2
&lt;span class="nb"&gt;cat &lt;/span&gt;file1 file2 file3 | &lt;span class="nb"&gt;tee &lt;/span&gt;combo.txt | &lt;span class="nb"&gt;wc&lt;/span&gt; &lt;span class="nt"&gt;-w&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jMLGfCFx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/erzmk77oyx9eb6tql36h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jMLGfCFx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/erzmk77oyx9eb6tql36h.png" alt="Image description" width="745" height="246"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>codenewbie</category>
      <category>100daysofcode</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Working with Files through the Command Line</title>
      <dc:creator>Mustafa Hashmani</dc:creator>
      <pubDate>Mon, 07 Aug 2023 10:05:47 +0000</pubDate>
      <link>https://dev.to/mustafahashmani/working-with-files-through-the-command-line-772</link>
      <guid>https://dev.to/mustafahashmani/working-with-files-through-the-command-line-772</guid>
      <description>&lt;h2&gt;
  
  
  &lt;code&gt;cat&lt;/code&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The cat command con*&lt;em&gt;cat&lt;/em&gt;*enates and prints the contents of files.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;cat &amp;lt;filename&amp;gt;&lt;/code&gt; will read the contents of a file and print them out. For example, &lt;code&gt;cat instructions.txt&lt;/code&gt; will read in from the instructions.txt file and then print the contents out to the screen.&lt;/li&gt;
&lt;li&gt;If we provide cat with multiple files, it will concatenate their contents and output them.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;cat peanutbutter.js jelly.css&lt;/code&gt; will output peanutbutter.js first and immediately after print the contents of jelly.css&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; &amp;lt;filename&amp;gt;
&lt;span class="nb"&gt;cat&lt;/span&gt; &amp;lt;file1&amp;gt; &amp;lt;file2&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;less&lt;/code&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;less&lt;/code&gt; command displays the contents of a file, one page at a time. We can navigate forwards and backwards through the file, which is especially useful with very large files.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;less somefile.txt&lt;/code&gt; will display the contents of somefile.txt using less.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When viewing a file using less :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;press &lt;strong&gt;space&lt;/strong&gt; to go to the next page of the file&lt;/li&gt;
&lt;li&gt;press &lt;strong&gt;b&lt;/strong&gt; to go back to the previous page&lt;/li&gt;
&lt;li&gt;press &lt;strong&gt;Enter&lt;/strong&gt; or &lt;strong&gt;Down arrow&lt;/strong&gt; to scroll by one line&lt;/li&gt;
&lt;li&gt;to search, type forward slash &lt;strong&gt;/&lt;/strong&gt; followed by a pattern&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;press &lt;strong&gt;q&lt;/strong&gt; to quit&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;less &amp;lt;filename&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;tac&lt;/code&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;tac (cat spelled backwards) will concatenate and print files in reverse. It prints each line of a file, starting with the last line. You can think of it as printing in reverse "vertically"&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;tac &lt;/span&gt;file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FUgMmjJi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3buf156hbm6aqkj8tapv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FUgMmjJi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3buf156hbm6aqkj8tapv.png" alt="tac" width="703" height="75"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;rev&lt;/code&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The &lt;code&gt;rev&lt;/code&gt; command prints the contents of a file, reversing the order of each line. Think of it as a "horizontal" reverse, whereas tac is a "vertical" reverse.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;rev file.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Xipw0bfj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zxrb7ll1tp13dgvo7977.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Xipw0bfj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zxrb7ll1tp13dgvo7977.png" alt="rev" width="690" height="78"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;head&lt;/code&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The head command prints a portion of a file, starting from the beginning of the file. By default, it prints the first 10 lines of a file.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;head warAndPeace.txt&lt;/code&gt; would print the first 10 lines of the warAndPeace.txt file&lt;/li&gt;
&lt;li&gt;We can also specify a number of lines for head to print using the &lt;strong&gt;-n&lt;/strong&gt; option (or --lines) followed by an integer.&lt;/li&gt;
&lt;li&gt;head -n 21 warAndPeace.txt would print the first 21 lines of the warAndPeace.txt file&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We can also use an even shorter syntax to specify a number of lines: &lt;code&gt;head -3 filename.txt&lt;/code&gt; will print the first 3 lines of the file.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;head &lt;/span&gt;filename.txt
&lt;span class="nb"&gt;head&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; 13 filename.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;tail&lt;/code&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The tail command works similarly to the head command, except it prints from the END of a file. By default, it prints the last 10 lines of a file.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;tail warAndPeace.txt&lt;/code&gt; would print the last 10 lines of the warAndPeace.txt file&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The same -n option with head also works with the tail command.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;tail &lt;/span&gt;filename.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;wc&lt;/code&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The word count command can tell us the number of words, lines, or bytes in files. By default, it prints out three numbers: the lines, words, and bytes in a file.&lt;/li&gt;
&lt;li&gt;We can use the &lt;strong&gt;-l&lt;/strong&gt; option to limit the output to the number of lines.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The &lt;strong&gt;-w&lt;/strong&gt; option limits the output to the number of words in the file.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;wc&lt;/span&gt; &lt;span class="nt"&gt;-l&lt;/span&gt; students.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;sort&lt;/code&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The sort command outputs the sorted contents of a file (it does not change the file itself). By default, it will sort the lines of a file alphabetically.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sort names.txt&lt;/code&gt; would print each line from names.txt, sorted in alphabetical order&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;-r&lt;/strong&gt; option tells the sort command to sort in reverse order.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;sort names.txt -r&lt;/code&gt; would print each line from names.txt, sorted in REVERSE alphabetical order.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sort &lt;/span&gt;filename.txt
&lt;span class="nb"&gt;sort&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; filename.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;
  
  
  Sorting Numerically
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;-n&lt;/strong&gt; option tells the sort command to sort using numerical order.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sort -n prices.txt&lt;/code&gt; would print each line from names.txt, sorted in numerical order.&lt;/li&gt;
&lt;li&gt;We could also reverse it with &lt;code&gt;sort -nr prices.txt&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The &lt;strong&gt;-u&lt;/strong&gt; option tells the sort command to ignore duplicates and instead only sort unique values&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sort&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; prices.txt
&lt;span class="nb"&gt;sort&lt;/span&gt; &lt;span class="nt"&gt;-u&lt;/span&gt; prices.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>linux</category>
      <category>shell</category>
      <category>terminal</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
