<?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: LuCaS</title>
    <description>The latest articles on DEV Community by LuCaS (@delucasso).</description>
    <link>https://dev.to/delucasso</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%2F752418%2F2003ab67-0e72-4ece-aacf-836e1f3b969b.jpg</url>
      <title>DEV Community: LuCaS</title>
      <link>https://dev.to/delucasso</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/delucasso"/>
    <language>en</language>
    <item>
      <title>How to use GIT in shell (basics)</title>
      <dc:creator>LuCaS</dc:creator>
      <pubDate>Fri, 07 Oct 2022 04:25:19 +0000</pubDate>
      <link>https://dev.to/delucasso/how-to-use-git-in-shell-basics-2aij</link>
      <guid>https://dev.to/delucasso/how-to-use-git-in-shell-basics-2aij</guid>
      <description>&lt;p&gt;On my full-stack developer journey I've found, that making notes during your learning is a great way to remember stuff. You can also go back to your notes, if you need some help.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If you are new to GIT, you can should read a git handbook here:&lt;/strong&gt; [&lt;a href="https://docs.github.com/en/get-started/using-git/about-git" rel="noopener noreferrer"&gt;https://docs.github.com/en/get-started/using-git/about-git&lt;/a&gt;]&lt;/p&gt;

&lt;h4&gt;
  
  


&lt;/h4&gt;
&lt;p&gt;(&lt;a href="https://learngitbranching.js.org/" rel="noopener noreferrer"&gt;https://learngitbranching.js.org/&lt;/a&gt;)&lt;/p&gt;
&lt;h2&gt;
  
  
  I summarized basics here.
&lt;/h2&gt;

&lt;p&gt;When we are in a local bash and in particular project directory, here is what we can do.&lt;/p&gt;
&lt;h4&gt;
  
  
  git phases are:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;WORKING DIRECTORY&lt;/li&gt;
&lt;li&gt;STAGING AREA&lt;/li&gt;
&lt;li&gt;LOCAL REPOSITORY&lt;/li&gt;
&lt;li&gt;REMOTE REPOSITORY&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  1. To &lt;strong&gt;INITIALIZE&lt;/strong&gt; a git
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;git init&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  2. To &lt;strong&gt;INCLUDE ALL FILES&lt;/strong&gt; (those listed in .gitignore are omited
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;git add .&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Premade templates for .gitignore files
&lt;/h4&gt;

&lt;p&gt;[&lt;a href="https://github.com/github/gitignore" rel="noopener noreferrer"&gt;https://github.com/github/gitignore&lt;/a&gt;]&lt;/p&gt;

&lt;h4&gt;
  
  
  3. To &lt;strong&gt;CREATE A LOCAL STAGE&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;git commit -m "Initial Commit"&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  4. To &lt;strong&gt;PUSH&lt;/strong&gt; commits to a remote repository
&lt;/h4&gt;

&lt;p&gt;Push the git to the origin main (remote)&lt;br&gt;
Don't forget to commit changes first, then  :&lt;/p&gt;

&lt;p&gt;&lt;em&gt;$ git commit -m "Your commit stage description"&lt;/em&gt;&lt;br&gt;
&lt;em&gt;git remote add origin &lt;a href="https://github.com/DeLucasso/NAME_OF_GIT.git" rel="noopener noreferrer"&gt;https://github.com/DeLucasso/NAME_OF_GIT.git&lt;/a&gt;&lt;/em&gt;&lt;br&gt;
&lt;em&gt;git branch -m main&lt;/em&gt;&lt;br&gt;
&lt;em&gt;git push -u origin main&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  5. To &lt;strong&gt;RESET&lt;/strong&gt; to some specifid commit
&lt;/h4&gt;

&lt;p&gt;Use &lt;em&gt;git log&lt;/em&gt; command to find a hash of commit that you'd like to reset back to.&lt;br&gt;
&lt;em&gt;git reset --hard [hash]&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  6. If you want to &lt;strong&gt;PRESERVE&lt;/strong&gt; your work, you can use the stash command:
&lt;/h4&gt;

&lt;p&gt;_git stash&lt;br&gt;
git reset --hard [hash]&lt;br&gt;
git stash pop&lt;br&gt;
_&lt;/p&gt;

&lt;h4&gt;
  
  
  7. To &lt;strong&gt;IGNORE&lt;/strong&gt; (omit) files from the git repository to be uploaded to GitHub: First create a hidden file gitignore
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;touch .gitignore&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  8. To &lt;strong&gt;ADD&lt;/strong&gt; files to the .gitignore file
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;open .gitignore&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  9. To &lt;strong&gt;REMOVE ALL&lt;/strong&gt; files from git stage
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;git -rm --cashed -r .&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  10. To &lt;strong&gt;REMOVE SINGLE&lt;/strong&gt; file from git stage
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;git -rm --cashed filename.txt&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  11. To &lt;strong&gt;GET A STATUS&lt;/strong&gt; a status of git
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;git status&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  12. To &lt;strong&gt;GET A LOG&lt;/strong&gt; of the git stage
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;git log&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  13. To put a &lt;strong&gt;COMMENT&lt;/strong&gt; into .gitignore use
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;#This is a comment line in .gitignore&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  14. To use &lt;strong&gt;WILDCARDS&lt;/strong&gt; in .gitignore
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;*.txt&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging" rel="noopener noreferrer"&gt;An article to understand git branching:&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  15. To &lt;strong&gt;MAKE A NEW&lt;/strong&gt; a new branch
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;git branch -m new_branch_name&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  16. To &lt;strong&gt;CHECK&lt;/strong&gt; branch list
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;git branch&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  17. To &lt;strong&gt;SWITCH&lt;/strong&gt; a branch ( Check Out ), then you can see '*' at
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;git checkout branch_name&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  19. To &lt;strong&gt;RENAME&lt;/strong&gt; a local branch
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;git -m old_name new_name&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  20. To &lt;strong&gt;DELETE&lt;/strong&gt; a LOCAL branch
&lt;/h4&gt;

&lt;p&gt;First you have to checkout a branch that you want to delete (if its' marked as *)&lt;br&gt;
Then you can delete a branch&lt;br&gt;
&lt;em&gt;git -d branch_name_to_delete&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  21. To &lt;strong&gt;DELETE&lt;/strong&gt; a REMOTE branch
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;git push origin --delete branch_name&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  22.!! Everytime when you want to &lt;strong&gt;COMMIT&lt;/strong&gt; changes to the git, you have to do this every time:
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;git add .&lt;/em&gt; // (to include all files to git)&lt;br&gt;
&lt;em&gt;git commit -m "Your commit comment of the changes you've made"&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  21. To &lt;strong&gt;MERGE&lt;/strong&gt; a branch to main, don't forget to add all files and commit changes first!
&lt;/h4&gt;

&lt;p&gt;First if you are happy with the changes in branch, you can merge the branch with main&lt;/p&gt;

&lt;p&gt;&lt;em&gt;git checkout main&lt;/em&gt;&lt;br&gt;
&lt;em&gt;git merge name_of_branch_that_you_want_to_merge&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The vim editor will open, so you can add comments to merge. Then to save it, just write:&lt;br&gt;
 &lt;em&gt;:q!&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  That's it folks. I wrote everything in an order, that you will probably use it. I hope it help you with a git commands in shell.
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/DeLucasso/git/blob/main/how_to_use_git.txt" rel="noopener noreferrer"&gt;Here is my github repo:&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fuabfruzfx881xc4pm0wp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fuabfruzfx881xc4pm0wp.png" alt="Image description" width="800" height="750"&gt;&lt;/a&gt;&lt;/p&gt;

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