<?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: Dan</title>
    <description>The latest articles on DEV Community by Dan (@cookrdan).</description>
    <link>https://dev.to/cookrdan</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%2F143306%2F5edc4ca9-e430-4d7e-a1fd-1a1bc9614155.jpeg</url>
      <title>DEV Community: Dan</title>
      <link>https://dev.to/cookrdan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cookrdan"/>
    <language>en</language>
    <item>
      <title>Cloud Storage that ignores node_modules with a filter file</title>
      <dc:creator>Dan</dc:creator>
      <pubDate>Mon, 23 Dec 2019 06:45:04 +0000</pubDate>
      <link>https://dev.to/cookrdan/cloud-storage-that-ignores-nodemodules-with-an-ignore-file-376d</link>
      <guid>https://dev.to/cookrdan/cloud-storage-that-ignores-nodemodules-with-an-ignore-file-376d</guid>
      <description>&lt;p&gt;I have been using dropbox for a long time and even though I remain on the free plan I have never filled up the space. Important things live on there - and my laptop ever died somehow, I'd be okay.&lt;/p&gt;

&lt;p&gt;But one frustration I have had is that there is no way to &lt;em&gt;not&lt;/em&gt; sync certain folders - and this is a bigger problem with node_modules. Syncing thousands of files is ridiculously slow.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: you can selective sync with a paid dropbox account. I'm not paying for that.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This issue continued to perplex me. I did find pnpm which reduces amount of files used, but that didn't really solve the problem.&lt;/p&gt;

&lt;p&gt;So I went searching for another cloud provider. Hopefully it would give me a folder that I could use - like &lt;code&gt;.syncignore&lt;/code&gt; similar to how &lt;code&gt;.gitignore&lt;/code&gt; files work.&lt;/p&gt;

&lt;h3&gt;
  
  
  Trail and Error
&lt;/h3&gt;

&lt;p&gt;I did try sync.com which offers a free package, is decent, and allows you to selectively sync via the UI. This is &lt;em&gt;okay&lt;/em&gt;. But it's not ideal either.&lt;/p&gt;

&lt;p&gt;Along the way I ran into another service from Switzerland that has a great feature set from &lt;a href="//tresorit.com"&gt;https://tresorit.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;During my first attempt using Tresorit I felt it was slow. But I tried again, and it was just fine. So I jumped in further, because I found out that Tresorit allows you to create a filter for syncing - kind of like a &lt;code&gt;.gitignore&lt;/code&gt; file.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting it up
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: set up an account, install the desktop software, etc. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2&lt;/strong&gt;: In the software, make a new Tresor (let's try ~/projects).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3&lt;/strong&gt;: Make a rule to filter all node_modules in every sub folder in ~/projects&lt;/p&gt;

&lt;p&gt;&lt;em&gt;You can read through &lt;a href="https://support.tresorit.com/hc/en-us/articles/217103697-Exclude-specific-file-types-from-sync-advanced-"&gt;this documentation&lt;/a&gt; which is buried a little bit on their site.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ~/projects
mkdir -p .tresorit/Filters
echo "[Ignore] //node_modules" &amp;gt; .tresorit/Filters/local.filter
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will add an ignore rule for &lt;em&gt;all&lt;/em&gt; sub-directories named &lt;code&gt;node_modules&lt;/code&gt;. They won't be synced. Brilliant.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: Make a test project and see how it works.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ~/projects
mkdir test-project &amp;amp;&amp;amp; cd test-project
npm init -y
npm install [some package]
ls
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;(you will see your node_modules folder here)&lt;/p&gt;

&lt;p&gt;Now check in the Tresorit desktop app and see what was synced - you will not see your node_modules folder. You should see &lt;code&gt;package.json&lt;/code&gt; and &lt;code&gt;package-lock.json&lt;/code&gt;&lt;/p&gt;




&lt;p&gt;Summary: Now you have one file with one rule in your ~/projects that filters all sub-directories name node_modules. Nifty.&lt;/p&gt;

&lt;p&gt;Happy npm-ing!&lt;/p&gt;

</description>
      <category>node</category>
      <category>npm</category>
      <category>cloudstorage</category>
    </item>
    <item>
      <title>Markdown to Pages format conversion</title>
      <dc:creator>Dan</dc:creator>
      <pubDate>Fri, 25 Oct 2019 01:25:33 +0000</pubDate>
      <link>https://dev.to/cookrdan/markdown-to-pages-format-conversion-7ii</link>
      <guid>https://dev.to/cookrdan/markdown-to-pages-format-conversion-7ii</guid>
      <description>&lt;p&gt;I write a lot of things in Markdown and use Pandoc for a number of things. I haven't been able to find a way to convert markdown to pages format. At times I need to send a document in either docx or pages. It's easier in pages.&lt;/p&gt;

&lt;p&gt;Pandoc of course is essential:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pandoc -o document.docx document.md 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It'd be great if I could get .docx to .pages conversion working in the command line somehow. So I fiddled. For too long.&lt;/p&gt;

&lt;p&gt;Apple Script is able to accomplish this - and here is the basic thing of it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;set old_doc to POSIX file "/Users/username/path/to/docx/file.docx" as string

set new_doc to POSIX file "/Users/username/path/to/pages/file.pages" as string

tell application "Pages"
    set thisDoc to open old_doc
    save thisDoc in file new_doc
    close thisDoc
end tell
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Note: if you don't tell Pages to &lt;code&gt;activate&lt;/code&gt; then this process will probably remain hidden behind other open windows - it's also quite fast&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I have yet to finish this little project. I plan to script it out more using &lt;code&gt;osascript&lt;/code&gt; so that I will just be able to type &lt;code&gt;mdtopages document.md&lt;/code&gt; in my terminal and end up with &lt;code&gt;document.pages&lt;/code&gt;.&lt;/p&gt;

</description>
      <category>commandline</category>
      <category>applescript</category>
      <category>markdown</category>
    </item>
    <item>
      <title>State of CSS Survey 2019 Results</title>
      <dc:creator>Dan</dc:creator>
      <pubDate>Thu, 13 Jun 2019 07:55:28 +0000</pubDate>
      <link>https://dev.to/cookrdan/state-of-cas-survey-2019-results-1c2p</link>
      <guid>https://dev.to/cookrdan/state-of-cas-survey-2019-results-1c2p</guid>
      <description>&lt;p&gt;&lt;em&gt;I’m just passing on news here&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The results for the State of CSS Survey that some of you may have taken have been compiled. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://2019.stateofcss.com/"&gt;Here is the website&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There’s some very interesting things in there! Enjoy!&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
    <item>
      <title>MacOS won’t be shipped with scripting languages in the future. (Python/Ruby/Perl/etc)</title>
      <dc:creator>Dan</dc:creator>
      <pubDate>Fri, 07 Jun 2019 13:44:42 +0000</pubDate>
      <link>https://dev.to/cookrdan/macos-won-t-be-shipped-with-scripting-languages-in-the-future-python-ruby-perl-etc-596o</link>
      <guid>https://dev.to/cookrdan/macos-won-t-be-shipped-with-scripting-languages-in-the-future-python-ruby-perl-etc-596o</guid>
      <description>&lt;p&gt;I just saw &lt;a href="https://www.macobserver.com/analysis/macos-catalina-deprecates-unix-scripting-languages/"&gt;this article&lt;/a&gt;. I’m just passing this along in case you didn’t  know like me. &lt;strong&gt;I recommend reading that article&lt;/strong&gt; but the short and sweet version is that MacOS 10.15 (Catalina) has depreciations and 10.16 will not be shipped with scripting languages. &lt;/p&gt;

&lt;p&gt;As they've quoted in the article, I'll share the important part from the &lt;a href="https://developer.apple.com/documentation/macos_release_notes/macos_10_15_beta_release_notes"&gt;MacOS 10.15 beta release notes&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Scripting language runtimes such as Python, Ruby, and Perl are included in macOS for compatibility with legacy software. Future versions of macOS won’t include scripting language runtimes by default, and might require you to install additional packages. If your software depends on scripting languages, it’s recommended that you bundle the runtime within the app. (49764202)&lt;/p&gt;

&lt;p&gt;Use of Python 2.7 isn’t recommended as this version is included in macOS for compatibility with legacy software. Future versions of macOS won’t include Python 2.7. Instead, it’s recommended that you run python3 from within Terminal. (51097165)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I was a little shocked to see this but then also not shocked at the same time. &lt;/p&gt;

&lt;p&gt;Any thoughts?&lt;/p&gt;

</description>
      <category>macos</category>
      <category>python</category>
      <category>perl</category>
      <category>ruby</category>
    </item>
    <item>
      <title>Snippet Management</title>
      <dc:creator>Dan</dc:creator>
      <pubDate>Thu, 06 Jun 2019 14:55:11 +0000</pubDate>
      <link>https://dev.to/cookrdan/snippet-management-437i</link>
      <guid>https://dev.to/cookrdan/snippet-management-437i</guid>
      <description>&lt;p&gt;Do you store and manage snippets of code? If you do, how do you do it? Do you use a snippet manager? &lt;/p&gt;

&lt;p&gt;I think I need to do something.&lt;/p&gt;

&lt;p&gt;I see that &lt;a href="https://hackjutsu.com/Lepton/"&gt;Lepton&lt;/a&gt; was ranked high on &lt;a href="https://www.slant.co/topics/7247/~code-snippets-manager#10"&gt;this site&lt;/a&gt;. I'm leery of it being Electron based though.&lt;/p&gt;

&lt;p&gt;I tried Boostnote when it was still a baby. I think the way it stored things wasn't ideal for me though - if I remember right. &lt;/p&gt;

&lt;p&gt;What about you?&lt;/p&gt;

</description>
      <category>snippets</category>
      <category>discuss</category>
    </item>
    <item>
      <title>MacOS Catalina will use zsh for the default shell</title>
      <dc:creator>Dan</dc:creator>
      <pubDate>Tue, 04 Jun 2019 13:06:31 +0000</pubDate>
      <link>https://dev.to/cookrdan/macos-catalina-will-use-zsh-for-the-default-shell-oii</link>
      <guid>https://dev.to/cookrdan/macos-catalina-will-use-zsh-for-the-default-shell-oii</guid>
      <description>&lt;h3&gt;
  
  
  The News
&lt;/h3&gt;

&lt;p&gt;I'm just catching up on news from WWDC and this seemed to be something that wasn't written in many places. Maybe some of you like me also aren't aware.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.theverge.com/2019/6/4/18651872/apple-macos-catalina-zsh-bash-shell-replacement-features"&gt;Here's a link&lt;/a&gt; to an article on The Verge that discusses it more and the potential reasoning. &lt;/p&gt;

&lt;p&gt;In case you were wondering, Bash will still be available in MacOS Catalina.&lt;/p&gt;

&lt;p&gt;I'm still a bit of a newb with Bash/Terminal/etc. but I've read that a lot of people love zsh. So, I'm going to install zsh right now and write as I go. I'm personally going to hold off on making it my default because I'm going to break something if I do. Actually, a lot of things will break. Will do that later.&lt;/p&gt;

&lt;h3&gt;
  
  
  How to Install it
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;On MacOS the easy way is with homebrew: &lt;code&gt;brew install zsh&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Open Terminal and type zsh&lt;/li&gt;
&lt;li&gt;You will have various prompts for setting up configs.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Want to make it the default shell?
&lt;/h3&gt;

&lt;p&gt;According to &lt;a href="http://osxdaily.com/2018/12/29/use-zsh-default-terminal-mac-os-x/"&gt;this&lt;/a&gt; open Terminal preferences &amp;gt; General &amp;gt; "Shells open with" &amp;gt; "Command" type in &lt;code&gt;/bin/zsh/&lt;/code&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  Oh-my-zsh
&lt;/h3&gt;

&lt;p&gt;Explore &lt;a href="https://github.com/robbyrussell/oh-my-zsh"&gt;oh-my-zsh&lt;/a&gt; which I have yet to do because WOW there is SO MUCH!&lt;/p&gt;

&lt;h3&gt;
  
  
  Other Reading
&lt;/h3&gt;

&lt;p&gt;This article from &lt;a class="comment-mentioned-user" href="https://dev.to/aspittel"&gt;@aspittel&lt;/a&gt;
 here on dev.to about using iTerm2 and zsh was linked from elsewhere as well. &lt;a href="https://dev.to/aspittel/my-terminal-setup-iterm2--zsh--30lm"&gt;Read here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/nyanev/how-to-use-zsh-in-vs-code-for-mac-39dp"&gt;Use zsh in VSCode&lt;/a&gt; from &lt;a class="comment-mentioned-user" href="https://dev.to/nyanev"&gt;@nyanev&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>macos</category>
      <category>terminal</category>
      <category>bash</category>
      <category>zsh</category>
    </item>
    <item>
      <title>Source or Symlink or Other?</title>
      <dc:creator>Dan</dc:creator>
      <pubDate>Fri, 10 May 2019 06:40:50 +0000</pubDate>
      <link>https://dev.to/cookrdan/source-or-symlink-or-other-4a9a</link>
      <guid>https://dev.to/cookrdan/source-or-symlink-or-other-4a9a</guid>
      <description>&lt;h2&gt;
  
  
  Source or Symlink or Other?
&lt;/h2&gt;

&lt;p&gt;I'm looking for some insight. I started getting into bash/terminal/etc on my mac since around January and now I use it quite a lot. I started making some small scripts to automate some things that I do and it's great! &lt;/p&gt;

&lt;p&gt;I realized when I started that I wanted to keep scripts in a different place (cloud). I don't need to sync anything to other machines, but it's just convenient for the once in a while format that I do. So I created the following set up:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Everything is stored in my dropbox &lt;code&gt;~/dropbox/.bash/scripts/&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;I have a script called &lt;code&gt;init.sh&lt;/code&gt; that will look in &lt;code&gt;~/dropbox/.bash/scripts/&lt;/code&gt; and then &lt;strong&gt;source&lt;/strong&gt; each script. So then each script is I believe loaded into memory(?). &lt;code&gt;init.sh&lt;/code&gt; also contains many other things like my prompt customization etc.&lt;/li&gt;
&lt;li&gt;Each script contains a function - and so when I use the script I'm not using the script name, just a function name (since I source it.&lt;/li&gt;
&lt;li&gt;my &lt;code&gt;~/.bash_profile&lt;/code&gt; only has one line: &lt;code&gt;source ~/dropbox/.bash/init.sh&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So for example, a script called &lt;code&gt;hello.sh&lt;/code&gt; might be like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#/bin/bash&lt;/span&gt;

&lt;span class="k"&gt;function &lt;/span&gt;hello &lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"hello world"&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then in my &lt;code&gt;init.sh&lt;/code&gt; script it will do &lt;code&gt;source hello.sh&lt;/code&gt; and I can call the &lt;code&gt;hello&lt;/code&gt; function from terminal.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is recommended?
&lt;/h3&gt;

&lt;p&gt;I made this set up and it works, but it was when I didn't know a lot. I now know the common way to do things is by using symlinks. Is there anyone that can share some insight about why one way is better than another? Or is there another way that only code ninjas know?&lt;/p&gt;

</description>
      <category>bash</category>
      <category>help</category>
    </item>
    <item>
      <title>Using Git on iOS (the free way)</title>
      <dc:creator>Dan</dc:creator>
      <pubDate>Sat, 27 Apr 2019 08:29:35 +0000</pubDate>
      <link>https://dev.to/cookrdan/using-git-on-ios-1l1n</link>
      <guid>https://dev.to/cookrdan/using-git-on-ios-1l1n</guid>
      <description>&lt;h1&gt;
  
  
  Using Git on iOS
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;I mention two apps- I have no affiliation...just sharing something&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I recently discovered fairly new iOS app called &lt;a href="https://itunes.apple.com/ca/app/ishell/id1455946930?mt=8" rel="noopener noreferrer"&gt;iShell&lt;/a&gt;. In short it's Alpine Linux. I was excited to see this and I couldn't help myself from tinkering with it. It comes with a package manager (apk). I was able to install bash (google it) and change how the prompt looks and etc. Not &lt;em&gt;everything&lt;/em&gt; that you would expect is in there and some things probably just don’t work (because apps have limited access to  device hardware etc).&lt;/p&gt;

&lt;p&gt;I was also curious about getting git to work. Short answer: yes, it works. The printed output for some things like &lt;code&gt;git log&lt;/code&gt; is a bit wonky but it does work. I haven't tried yet but it'd probably be better on iPad with the bigger screen. The version that installed with the package manager is 2.20.1.&lt;/p&gt;

&lt;p&gt;(Edit: manually adding the less pager made the output from git that uses a pager to be normal)&lt;/p&gt;

&lt;h3&gt;
  
  
  Okay but is it really useable for git??
&lt;/h3&gt;

&lt;p&gt;Git works, but what about editing files? iShell comes with Vim and I also installed nano and set that as the editor for git. But what about using other iOS apps as an editor?&lt;/p&gt;

&lt;p&gt;Yesterday I discovered that iShell shows up in the iOS Files app as a source. Everything on the system is accessible and the home folder &lt;code&gt;~/&lt;/code&gt; is &lt;code&gt;/root&lt;/code&gt; when you're browsing the structure. Now the interesting part is that, as you may know, those files are accessible by apps that utilize the iOS Files document picker. &lt;/p&gt;

&lt;p&gt;So, for example, with an editor app like &lt;a href="https://itunes.apple.com/ca/app/kodex/id1038574481?mt=8" rel="noopener noreferrer"&gt;Kodex&lt;/a&gt; you can access files stored in iShell. Make edits. Then you do all your normal git commands in iShell. &lt;/p&gt;

&lt;p&gt;On iPad, iShell supports split screen so you could have an editor on one half and iShell on the other, or slide over. You know: touch touch tap tap git. &lt;/p&gt;

&lt;p&gt;I have not tested this thoroughly but I believe everything should work correctly. Both iShell and Kodex are free and so this is a free way to use git and remote repos on iOS. &lt;/p&gt;

&lt;p&gt;Edit: heres a screenshot on ipad&lt;br&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%2Fnfkxotp9tysu4hqasxer.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%2Fnfkxotp9tysu4hqasxer.png" alt="git on ios"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ios</category>
      <category>git</category>
      <category>linux</category>
    </item>
    <item>
      <title>Best Practices for HTML</title>
      <dc:creator>Dan</dc:creator>
      <pubDate>Mon, 22 Apr 2019 22:57:19 +0000</pubDate>
      <link>https://dev.to/cookrdan/best-practices-for-html-31j5</link>
      <guid>https://dev.to/cookrdan/best-practices-for-html-31j5</guid>
      <description>&lt;p&gt;Hey Everyone,&lt;/p&gt;

&lt;p&gt;I’m not new to HTML as it’s been around for a long time but I’m somewhat new to developing for the web. &lt;/p&gt;

&lt;p&gt;Currently I’m reviewing some notes I have and looking up more information on MDN and I always like to see “best practices” as those are like gold nuggets. &lt;/p&gt;

&lt;p&gt;Sometimes it seems like best practices incorporate other factors that are not straightforward. For example creating a relationship between &lt;code&gt;&amp;lt;label&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; using &lt;code&gt;for&lt;/code&gt; and &lt;code&gt;id&lt;/code&gt; attributes respectively.&lt;/p&gt;

&lt;p&gt;So, what kind of sneaky best practices do you know of for HTML?&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>html</category>
      <category>bestpractices</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Conflict Resolution: Git Merge practice</title>
      <dc:creator>Dan</dc:creator>
      <pubDate>Tue, 02 Apr 2019 13:59:37 +0000</pubDate>
      <link>https://dev.to/cookrdan/conflict-resolution-git-merge-practice-3iab</link>
      <guid>https://dev.to/cookrdan/conflict-resolution-git-merge-practice-3iab</guid>
      <description>&lt;p&gt;&lt;em&gt;This assumes you have some basic knowledge of git and the command line (I use bash). For reference I’ve included a few of the commands used in the bottom with some definition.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I’m pretty new to git and the command line but I’d like to share a few things I’m learning. I've found that it is good to practice using git with a fake project right in the terminal. Just reading about git commands and what they do does not help experience using git itself. Admittedly it’s a bit intimidating to try some things on a real project. So, open up terminal and use this to practice merging a conflict. &lt;/p&gt;

&lt;p&gt;We're going to go through the process of doing a merge with a conflict in git. We will see what happens and then what needs to be done to resolve it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get Started and Create a Conflict
&lt;/h2&gt;

&lt;p&gt;First, set up a folder to use for this, change into that directory and then do the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git init
echo "line 1" &amp;gt; conflict.txt
git add .
git commit -m "line 1"
echo "line 2" &amp;gt;&amp;gt; conflict.txt
git commit -am "add line 2"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We are on the &lt;code&gt;master&lt;/code&gt; branch and now have a file (conflict.txt) that has two lines of text. &lt;/p&gt;

&lt;p&gt;Next, we are going to branch off and make more changes on this file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout -b morelines
echo "line 3" &amp;gt;&amp;gt; conflict.txt
git commit -am "add line 3"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We are on the &lt;code&gt;morelines&lt;/code&gt; branch. Right now conflict.txt on each branch looks like this:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Line #&lt;/th&gt;
&lt;th&gt;conflict.txt (master)&lt;/th&gt;
&lt;th&gt;conflict.txt (morelines)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;line 1&lt;/td&gt;
&lt;td&gt;line 1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;line 2&lt;/td&gt;
&lt;td&gt;line 2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt; &lt;/td&gt;
&lt;td&gt;line 3&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;If we were to now run &lt;code&gt;git checkout master&lt;/code&gt; followed by &lt;code&gt;git merge morelines&lt;/code&gt;, git will be able to merge with no conflict and it would be a fast-forward merge.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;BUT!&lt;/strong&gt; We want conflict! So we're going to get in a fight, sort of.&lt;/p&gt;

&lt;p&gt;Do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout master
echo "line 4" &amp;gt;&amp;gt; conflict.txt
git commit -am "add line 4"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you could look at both files side by side right now they'd be like this:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Line #&lt;/th&gt;
&lt;th&gt;conflict.txt (master)&lt;/th&gt;
&lt;th&gt;conflict.txt (morelines)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;line 1&lt;/td&gt;
&lt;td&gt;line 1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;line 2&lt;/td&gt;
&lt;td&gt;line 2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;line 4&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;line 3&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;You can see the conflict here. &lt;/p&gt;

&lt;h2&gt;
  
  
  Try the Merge
&lt;/h2&gt;

&lt;p&gt;Now let's try to merge the &lt;code&gt;morelines&lt;/code&gt; branch into the &lt;code&gt;master&lt;/code&gt; branch and see what happens. We are already on &lt;code&gt;master&lt;/code&gt; so do this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git merge morelines
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In our attempt to merge, git gives us this feedback:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Auto-merging conflict.txt&lt;br&gt;&lt;br&gt;
CONFLICT (content): Merge conflict in conflict.txt&lt;br&gt;&lt;br&gt;
Automatic merge failed; fix conflicts and then commit the result.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We have a conflict! Also note- git is in a merge process right now and expects us to do a few things. If you want to stop the merge process you can run &lt;code&gt;git merge --abort&lt;/code&gt;. But we aren’t going to do that. We are going to fix the conflict and finish the merge. &lt;/p&gt;

&lt;h2&gt;
  
  
  Fix The Conflicts
&lt;/h2&gt;

&lt;p&gt;In the above message, git tells us what to do next: "Fix conflicts and then commit the result."  In other words:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Open the conflicted file and merge the changes with edits.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Stage the change.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Run &lt;code&gt;git commit&lt;/code&gt; to finish the merge process (this will make a merge commit).&lt;/p&gt;

&lt;p&gt;Before continuing, you may run &lt;code&gt;git status&lt;/code&gt; and read what it says. I’m not going to write about it here but just give it a good read. &lt;/p&gt;

&lt;p&gt;Next, let’s fix the conflict. &lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Open the conflicted file and merge the changes with edits.
&lt;/h3&gt;

&lt;p&gt;This means what it means. Nothing is automatic here. You have to look at the conflicted file with your eyeballs and manually make changes. &lt;/p&gt;

&lt;p&gt;Run &lt;code&gt;open conflict.txt&lt;/code&gt; to open the file. It will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;line 1
line 2
&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt; HEAD
line 4
=======
line 3
&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; morelines
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Well this certainly looks strange! Let’s break it down a little. We can easily see the text we put there ourselves. But git has added extra markers. They have meaning:&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;HEAD&lt;/code&gt; section shows the conflicted part of the currently checked out version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt; HEAD
line 4
=======
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above conflicts with the incoming change that is indicated by the &lt;code&gt;morelines&lt;/code&gt; section:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;======
line 3
&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; morelines
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In summary: there’s an incoming change from the branch we want to merge (&lt;code&gt;morelines&lt;/code&gt;) that conflicts with the version that we have checked out (&lt;code&gt;HEAD&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Git includes all of this to help us manually merge the changes. &lt;/p&gt;

&lt;p&gt;We will need to delete those markers and re-arrange the text a bit. For this to make sense visually, go ahead and edit the file so it looks like this in the end:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;line 1
line 2
line 3
line 4
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;As you can see, the lines we want are in the correct order, the marker lines are not there, and the separator line is gone. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Side Note: if you do not delete the markers that git placed in the file they will stay there. Git doesn’t take them away.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Side note, again: You can technically make any change you want at this point, but that is not the purpose of merging. Stick to merging changes together, not to making more changes. Save that for normal commits.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Save and close the file. &lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2 and 3: Stage and Commit
&lt;/h3&gt;

&lt;p&gt;In terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Your editor will come up with the commit text and git has conveniently included the commit message as &lt;code&gt;Merge branch 'morelines'&lt;/code&gt;. This is okay for our fake project so save it and close. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Side Note: you won’t be able to complete the merge until all conflicts are resolved. If need be, repeat steps 1 and 2 and in the end do the commit to finish the merge.&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;Merge complete! You can even check two things to be sure: &lt;code&gt;git status&lt;/code&gt; to show that we are on &lt;code&gt;master&lt;/code&gt; branch. To see our &lt;code&gt;line 3&lt;/code&gt; text from &lt;code&gt;morelines&lt;/code&gt; branch is merged into &lt;code&gt;conflict.txt&lt;/code&gt; you can run &lt;code&gt;cat conflict.txt&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;Resolving a merge conflict:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;git merge branchname&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;git will tell you there is a conflict (if any)&lt;/li&gt;
&lt;li&gt;Open and edit the conflicted file and merge the changes. Delete the references and separator that git puts in. &lt;/li&gt;
&lt;li&gt;Save the file. &lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;git add&lt;/code&gt; to stage your edit. &lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;git commit&lt;/code&gt; to complete the merge process. &lt;/li&gt;
&lt;li&gt;Done. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There could be more to a merge conflict than this, especially when merging someone else’s work into your work or something similar. More communication may be necessary and etc. But I hope this has been helpful just to see the basics. &lt;/p&gt;

&lt;h3&gt;
  
  
  Reference for some Commands
&lt;/h3&gt;

&lt;p&gt;Here’s a short definition for some of the commands we used. Git commands start with &lt;code&gt;git&lt;/code&gt;:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Command&lt;/th&gt;
&lt;th&gt;What it does&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;echo "text" &amp;gt; filename&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;write&lt;/strong&gt; "text" to the file &lt;code&gt;filename&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;echo "text" &amp;gt;&amp;gt; filename&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;append&lt;/strong&gt; "text" to the file &lt;code&gt;filename&lt;/code&gt; (notice the two arrows &lt;code&gt;&amp;gt;&amp;gt;&lt;/code&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;git add .&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;stage changes in current directory&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;git commit -am "message"&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;shortcut to stage &lt;em&gt;all&lt;/em&gt; changes in project (regardless of directory) and commit with a message. Equivalent of &lt;code&gt;git add -A; git commit -m "message"&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;git checkout -b branchname&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;shortcut to create a branch (if it doesn’t exist) then check it out. Equivalent of &lt;code&gt;git branch branchname; git checkout branchname&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>git</category>
      <category>cli</category>
      <category>beginners</category>
    </item>
    <item>
      <title>A few git help extras</title>
      <dc:creator>Dan</dc:creator>
      <pubDate>Sat, 23 Mar 2019 14:37:55 +0000</pubDate>
      <link>https://dev.to/cookrdan/a-few-git-help-extras-h53</link>
      <guid>https://dev.to/cookrdan/a-few-git-help-extras-h53</guid>
      <description>&lt;p&gt;On the command line &lt;code&gt;git help&lt;/code&gt; is very useful if you need a quick reference. But if you have ever tried using it, there's &lt;em&gt;a lot&lt;/em&gt; of information.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Use the &lt;code&gt;-h&lt;/code&gt; option for quick, simple reference
&lt;/h3&gt;

&lt;p&gt;Try appending the &lt;code&gt;-h&lt;/code&gt; option on commands to print out a simplified reference. Like this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;git checkout -h&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Use &lt;code&gt;git help&lt;/code&gt; all by itself
&lt;/h3&gt;

&lt;p&gt;Type in &lt;code&gt;git help&lt;/code&gt; in the command line and you get a list of common Git commands with a quick description.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use &lt;code&gt;git help -g&lt;/code&gt; for Guides
&lt;/h3&gt;

&lt;p&gt;Some may not know that these guides exist within &lt;code&gt;git help&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;〉 git help -g

The common Git guides are:
   attributes          Defining attributes per path
   cli                 Git command-line interface and conventions
   core-tutorial       A Git core tutorial for developers
   cvs-migration       Git for CVS users
   diffcore            Tweaking diff output
   everyday            A useful minimum set of commands for Everyday Git
   glossary            A Git Glossary
   hooks               Hooks used by Git
   ignore              Specifies intentionally untracked files to ignore
   modules             Defining submodule properties
   namespaces          Git namespaces
   repository-layout   Git Repository Layout
   revisions           Specifying revisions and ranges for Git
   tutorial            A tutorial introduction to Git
   tutorial-2          A tutorial introduction to Git: part two
   workflows           An overview of recommended workflows with Git

'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help &amp;lt;command&amp;gt;' or 'git help &amp;lt;concept&amp;gt;'
to read about a specific subcommand or concept.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;For example, try:  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;git help glossary&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Have a great day!&lt;/p&gt;

</description>
      <category>git</category>
      <category>beginners</category>
      <category>cli</category>
    </item>
  </channel>
</rss>
