<?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>Forem: Abhishek S. Sharma</title>
    <description>The latest articles on Forem by Abhishek S. Sharma (@imabtiwari).</description>
    <link>https://forem.com/imabtiwari</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%2F430805%2Fdc29c576-3529-4501-87e4-6043964e0003.jpg</url>
      <title>Forem: Abhishek S. Sharma</title>
      <link>https://forem.com/imabtiwari</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/imabtiwari"/>
    <language>en</language>
    <item>
      <title>Dockerize Angular App</title>
      <dc:creator>Abhishek S. Sharma</dc:creator>
      <pubDate>Sat, 08 Jan 2022 15:27:11 +0000</pubDate>
      <link>https://forem.com/imabtiwari/dockerize-angular-app-l3i</link>
      <guid>https://forem.com/imabtiwari/dockerize-angular-app-l3i</guid>
      <description>&lt;h2&gt;
  
  
  Agenda
&lt;/h2&gt;

&lt;p&gt;Dockerize an &lt;a href="https://angular.io/"&gt;Angular app&lt;/a&gt;, built with the &lt;a href="https://angular.io/cli"&gt;Angular CLI&lt;/a&gt;, using &lt;a href="https://docs.docker.com/engine/"&gt;Docker&lt;/a&gt;, In this blog we will have a walkthrough of angular 7 and dockerize it over node image(base). &lt;/p&gt;

&lt;p&gt;Here, we specifically focus on:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create an angular app using CLI and test it locally&lt;/li&gt;
&lt;li&gt;Create an image for dev environment with code Hot-reloading&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Project Setup
&lt;/h2&gt;

&lt;p&gt;Install the &lt;a href="https://github.com/angular/angular-cli"&gt;Angular CLI&lt;/a&gt; globally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g @angular/cli@7.3.10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Generate a new app aka “angular-microservice” using CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng new angular-microservice 
cd angular-microservice
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(optional)To generate in present dir use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ng new angular-microservice –directory ./
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Docker Setup
&lt;/h2&gt;

&lt;p&gt;Add a Dockerfile to the project root:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# base image
FROM node:12.2.0

# set working directory
WORKDIR /app
# install and cache app dependencies
COPY package.json /app/package.json
RUN npm install
RUN npm install -g @angular/cli@7.3.10

# add app
COPY . /app

# start app
CMD ng serve --host 0.0.0.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Building Docker image&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker build -t angular-microservice:dev .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Run Docker Image&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Run the container after the build is done:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -d -v ${PWD}:/app -v /app/node_modules -p 4201:4200 --rm angular-microservice:dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use the -d flag to run the container in the background:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -d -v ${PWD}:/app -v /app/node_modules -p 4201:4200 --name foo --rm angular-microservice:dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please react if you found this blog helpful and informational.&lt;/p&gt;

</description>
      <category>angular</category>
      <category>docker</category>
      <category>tutorial</category>
      <category>bash</category>
    </item>
    <item>
      <title>Linux - I am Love with Terminal</title>
      <dc:creator>Abhishek S. Sharma</dc:creator>
      <pubDate>Sat, 22 Aug 2020 13:51:44 +0000</pubDate>
      <link>https://forem.com/imabtiwari/linux-i-am-love-with-terminal-2n7p</link>
      <guid>https://forem.com/imabtiwari/linux-i-am-love-with-terminal-2n7p</guid>
      <description>&lt;h3&gt;
  
  
  Forget your bird, Love Linux
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Click on playground and roll on your sleeves :c)&lt;/em&gt; -&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.katacoda.com/courses/ubuntu/playground"&gt;playground&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;There are four types of the shell, we have in Linux-&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Broune Shell -Sh shell&lt;/li&gt;
&lt;li&gt;C Shell - csh or tcsh &lt;/li&gt;
&lt;li&gt;Z shell -zsh &lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;My Favorite&lt;/em&gt; - Bourne again shell -bash  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;To check shell type-&lt;/strong&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;echo #SHELL &lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;To print on the terminal&lt;/strong&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;echo Hi from terminal !!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;To view the current directory, display absolute path, means path from the root&lt;/strong&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;pwd&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;To view all the files in a directory, -a will display hidden files as well&lt;/strong&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;ls &lt;br&gt;
ls -a&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;To change directory, it is case-sensitive, and you have to type in the name of the folder exactly as it is.&lt;/strong&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;cd .. - To go back from a folder to the folder before that&lt;br&gt;
cd my_directory - to goto my_directory folder &lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;When folder name has space e.g. my bird&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;cd my\ bird  &lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create a new directory&lt;/strong&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;mkdir abhishek&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;When folder name has a space e.g. abhishek sharma&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;mkdir abhishek\ sharma&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;make directory hierarchy from one command&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;mkdir -p /dir_1/dir_2/dir_3/dir_4&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Run multiple commands in a single line&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;cd abhishek\ sharma; mkdir devops_tools; ls&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create a file&lt;/strong&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;touch file_1.txt&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Write content in the file&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;cat &amp;gt; file_1.txt&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;write anything, write- "this is my first file in Linux" and type Ctrl+d to save&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;another way to do it&lt;/em&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;echo "this is my first file in linux" &amp;gt; file_1.txt&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;View content&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;cat file_1.txt&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Remove directory and file commands&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;mkdir removable_dir&lt;br&gt;
rmdir removable_dir&lt;br&gt;
mkdir removable_dir&lt;br&gt;
cd removable_dir; touch removable_file.txt&lt;br&gt;
rmdir removable_dir &lt;br&gt;
---&lt;em&gt;it gives you an error&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Notes:&lt;/strong&gt; &lt;em&gt;only blank directories can be deleted with rmdir; to delete a directory, which has content in it, we will use rm -r&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;rm -r removable_dir&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;To delete a file&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;rm file_1.txt&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Copy commands-&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Copy a file to another file&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;cp {options} source_file target_file&lt;br&gt;
cp new_file.txt copy_file.txt&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Copy File(s) to another directory or folder&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;cp {options} source_file target_directory &lt;br&gt;
touch /dir_1/dir_2/file_4.txt&lt;br&gt;
cp -v /dir_1/dir_2/file_4.txt /dir_1/dir_2/dir_3/dir_4&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Copy directory to directory&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;cp {options} source_directory target_directory &lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;To copy a directory from one place to another use -r or -R option in cp command&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;cp -r /dir_1/dir_2/dir_3/dir_4 /dir_1/dir_2/&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;If the destination directory already has the same file, still you want to copy that file, to overwrite it use *-i&lt;/em&gt;*&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;cat &amp;gt; dir_1/dir_2/file_4.txt - this is me. press ctrl+d&lt;br&gt;
cp -i /dir_1/dir_2/file_4.txt /dir_1/dir_2/dir_3/dir_4&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Move command- mv command to move the files one place to another&lt;/strong&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;touch dir_1/dir_2/file_3.txt&lt;br&gt;
mv -v dir_1/dir_2/file_3.txt dir_1/dir_2/dir_3&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Rename filename&lt;/strong&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;touch latest.txt&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;want to change this file name latest to new&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;mv latest.txt new.txt&lt;br&gt;
rm latest.txt&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Search something&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;locate new.txt&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;if you want to ignore the case&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;locate -i New.txt&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;if you want a file that has the word "this"&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;locate -i this&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;If you want the file(s) that has words "this" and "me"&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;locate -i *this*me&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;To view available disk space&lt;/strong&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;df &lt;br&gt;
&lt;em&gt;above command will show disk space in KB, to view in MB use the following command&lt;/em&gt;&lt;br&gt;
df -m&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;To view disk usage by files&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;du &lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;to view disk space used by a directory&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;du dir_1&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;To view Linux distro&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;uname &lt;br&gt;
uname -a &lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Package manager&lt;/strong&gt; &lt;em&gt;apt-get&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;sudo apt-get update &lt;br&gt;
sudo apt-get install nginx -y &lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;To view your IP and name in host or network&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;hostname &lt;br&gt;
hostname -I&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;To know your user account&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;whoami&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;To view user id, group id, group etc.&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;id&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Download a file from a link&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;curl &lt;a href="http://www.randomlink.com/downloadable-file.txt"&gt;www.randomlink.com/downloadable-file.txt&lt;/a&gt; -O&lt;br&gt;
OR&lt;br&gt;
wget &lt;a href="http://www.randomlink.com/downloadable-file.txt"&gt;www.randomlink.com/downloadable-file.txt&lt;/a&gt; -O downloadable-file&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Service start/stop/enable/disable/restart/status&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;systemctl status nginx&lt;br&gt;
systemctl restart nginx&lt;br&gt;
systemctl stop nginx&lt;br&gt;&lt;br&gt;
systemctl status nginx&lt;br&gt;
systemctl start nginx &lt;br&gt;
systemctl disable nginx&lt;br&gt;
systemctl enable nginx&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;To check connection to server&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;ping {ip address} &lt;br&gt;
ping &lt;a href="http://www.google.com"&gt;www.google.com&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Bonus to read&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Write &lt;em&gt;clear&lt;/em&gt; to clean the terminal.&lt;/li&gt;
&lt;li&gt;to autofill use TAB. Suppose you have a folder- &lt;em&gt;my_folder&lt;/em&gt; and want to go to that folder, You just need to type &lt;em&gt;cd my&lt;/em&gt; and then &lt;em&gt;TAB&lt;/em&gt; and the terminal fills the rest up and makes it &lt;em&gt;cd my_folder&lt;/em&gt;.&lt;/li&gt;
&lt;li&gt;To stop a command write &lt;em&gt;Ctrl+C&lt;/em&gt; &lt;/li&gt;
&lt;li&gt;to force stop a command write &lt;em&gt;Ctrl+Z&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Write &lt;em&gt;exit&lt;/em&gt; to exit from terminal&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>linux</category>
      <category>docker</category>
      <category>ubuntu</category>
      <category>bash</category>
    </item>
    <item>
      <title>ssh - a treat for your GitHub</title>
      <dc:creator>Abhishek S. Sharma</dc:creator>
      <pubDate>Sat, 08 Aug 2020 15:26:50 +0000</pubDate>
      <link>https://forem.com/imabtiwari/ssh-a-treat-for-your-github-18p2</link>
      <guid>https://forem.com/imabtiwari/ssh-a-treat-for-your-github-18p2</guid>
      <description>&lt;h3&gt;
  
  
  ssh commands
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;ssh creation&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;ssh key should be in /home/.ssh folder &lt;/li&gt;
&lt;li&gt;to generate ssh key- &lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;ssh-keygen&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;the command will ask you the name of the file, you can enter it. Let say, you named it "secure-shell" and follow the next instructions:&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;It will create two files in the same folder one is a public key file with extension .pub file and the other one is a private file. In our case, it will create "secure-shell.pub" and "secure-shell"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It needs your attention,&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;secure-shell - never share this with anybody&lt;br&gt;
secure-shell.pub -to be share with a remote server that you want to excess&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;When you have multiple private keys then you have to add a specific key to your main identity.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;eval $(ssh-agent)&lt;br&gt;
ssh-add ~/.ssh/secure-shell&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;difference ssh-add /.ssh/secure-shell V/S  ssh -i /.ssh/secure-shell ?&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;&lt;em&gt;add will set the identity of your system for a current pointed ssh key for every commit, whether -i will set temp identity pass key(ssh key) in case you have different ssh keys added to the different remote workspaces.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub access&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;write the following command to view the ssh-key (we will use secure-shell i.e. our key name). Please access the directory where your ssh key present.
&amp;gt; cat  .ssh/secure-shell.pub&lt;/li&gt;
&lt;li&gt;The above command lists a key, copy it!!&lt;/li&gt;
&lt;li&gt;Goto git account, setting &amp;gt; SSH and GPG keys &amp;gt; New ssh key and paste here &lt;/li&gt;
&lt;li&gt;that it &lt;/li&gt;
&lt;li&gt;Remember, you need to generate two ssh keys to access two different git accounts. Each git account will require a unique ssh key to be added. It is a good practice.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Remote access&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;On your local machine 
&amp;gt; cat  .ssh/secure-shell.pub&lt;/li&gt;
&lt;li&gt;The above command lists a key, copy it!!&lt;/li&gt;
&lt;li&gt;go to the remote machine and write following command 
&amp;gt; sudo vi .ssh/authorized_key &lt;/li&gt;
&lt;li&gt;Press i button to write &lt;/li&gt;
&lt;li&gt;paste your key here and press ESC button &lt;/li&gt;
&lt;li&gt;Write &lt;em&gt;:wq&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt; - &lt;em&gt;how to know which ssh is currently added&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;ssh-add -l&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;It's pretty simple, right !!&lt;/strong&gt; &lt;/p&gt;

</description>
      <category>git</category>
      <category>linux</category>
      <category>devops</category>
      <category>github</category>
    </item>
    <item>
      <title>Swing with git basic</title>
      <dc:creator>Abhishek S. Sharma</dc:creator>
      <pubDate>Fri, 24 Jul 2020 18:03:54 +0000</pubDate>
      <link>https://forem.com/imabtiwari/swing-with-git-basic-34fp</link>
      <guid>https://forem.com/imabtiwari/swing-with-git-basic-34fp</guid>
      <description>&lt;h2&gt;
  
  
  Draw your git sword
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Note-&lt;/strong&gt; &lt;em&gt;will start with the understanding of git commands&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To see present origin repo
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote -v 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;To add origin
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote add origin --remote repo URL-- 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;origin can be named anything but it should be remembered by you for future references &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;to set a new remote origin --remote repo url--&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote set-url origin --remote repo url-- 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Notes&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;set commit username (it sets globally, please change it if you want to change your name in other commits)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --global user.name "Abhishek Sharma" 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;set commit email
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config --global user.email "imabtiwari@gmail.com" 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;set user name in the previous commit if it is from another user name, it will open in vi editor press &lt;em&gt;i&lt;/em&gt; to insert words; to save it press- &lt;em&gt;ESC ":wq"&lt;/em&gt; or to save without an edit press *:q&lt;/li&gt;
&lt;li&gt;*
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit --amend --author="Abhishek Sharma &amp;lt;imabtiwari@gmail.com&amp;gt;" 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Kneel before git
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;to clone a repo&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone --remote repo url-- 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;branch creation&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;to create a new branch
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout -b _branchname_ 
git checkout -b _branchname-1 _
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;to switch branch from one to another (presently the branch is branchname-1)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout _branchname_
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;to track changes (it will show modified files)
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;to add a specific file
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add filename, filename2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to add all files at once&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;to commit on your local repo
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit -m "commit message"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to push changes on origin&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push origin _branchname_ 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Checkout to another branch to merge the changes in the branch
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout _branchname-2_
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;before the merge, we will take the latest pull from this remote branchname-2
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;now merge the branchname into branchname-2
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git merge branchname-2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;push changes back to the master branch
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push origin branchame-2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;branch deletion&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;delete the branch from the local system
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;delete the branch from a remote system
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push origin --delete _branchname_
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;git never forgets, it will help others to find your mistake and they blame you&lt;/strong&gt;&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;oneliner details
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git log --oneline 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Commit details&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It will show you changes of a specific commit
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git show commitID (hashcode)
e.g. git show 785767e
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;it points to the latest commit
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;to see head to the previous commit
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;to previous to the previous commit
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;strong&gt;Let understand the real git process in the companies with an example-&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;create a GitHub account or log in to your account &lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a repo "git-basic" in your git account&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;create a repo in the local system&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir git-basic
cd git-basic
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;We have only one branch -master for this repo&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;create a branch dev
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout -b dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;create a file named as git-basic
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch git-basic.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;create write in file - "I am a git ninja" and save (ctrl+s or cmd +s) this files &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;check this file to track the changes&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;the git-basic file is not staged right now, so we will add the file in the stage area
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add git-basic.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;we will commit the changes
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;now checkout to master branch to merge the changes
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;add remote repo (Github account repo)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote add origin -- remote repo url-- 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;pull the latest update from the origin in this branch
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;its time to merge the dev branch in master
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git merge dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;push the changes in the remote directory
&lt;/li&gt;
&lt;/ul&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;&lt;strong&gt;Hope, you like my post!&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thanks,&lt;/em&gt;&lt;br&gt;
&lt;strong&gt;Abhishek Sharma&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>devops</category>
      <category>linux</category>
    </item>
    <item>
      <title>Life-saving git commands</title>
      <dc:creator>Abhishek S. Sharma</dc:creator>
      <pubDate>Sat, 18 Jul 2020 14:26:30 +0000</pubDate>
      <link>https://forem.com/imabtiwari/life-saving-git-commands-42p0</link>
      <guid>https://forem.com/imabtiwari/life-saving-git-commands-42p0</guid>
      <description>&lt;h4&gt;
  
  
  1. Life-Saving git tips
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;We have two branches (dev and master) and one file in both branches with one commit for implementation of below scenarios&lt;/em&gt; &lt;/p&gt;

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

&lt;p&gt;touch file.txt&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;write something like- these are life-saving commands&lt;/em&gt;&lt;/p&gt;

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

&lt;p&gt;git add file.txt&lt;/p&gt;

&lt;p&gt;git commit -m “First Commit”&lt;/p&gt;

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

&lt;p&gt;git checkout dev&lt;/p&gt;

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

&lt;p&gt;&lt;em&gt;Now both branches have similar commits and in exact same condition, now we learn in this document the following commands&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;git diff &lt;/li&gt;
&lt;li&gt;git checkout&lt;/li&gt;
&lt;li&gt;git commit --amend &lt;/li&gt;
&lt;li&gt;git cherry-pick &lt;/li&gt;
&lt;li&gt;git reset (Soft, Mix, and Hard)&lt;/li&gt;
&lt;li&gt;git clean &lt;/li&gt;
&lt;li&gt;git reflog &lt;/li&gt;
&lt;li&gt;git revert &lt;/li&gt;
&lt;li&gt;print branch's hashcode&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. Gibberish fix in the file before commit check diff
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;add something in file write let say- asdfdsf adsdsd ssfdsf&lt;/li&gt;
&lt;li&gt;Check the differences&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;git diff&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;To fix this&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;checkout file.txt &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;- &lt;em&gt;Where you use this if you mistakenly unzip a file in the working directory and want to remove all these files&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  3.Fix wrong commit message
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Now we write next change in file.txt and add a new line - &lt;strong&gt;yes these tips are really helpful&lt;/strong&gt; &lt;/li&gt;
&lt;/ul&gt;

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

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

&lt;p&gt;git commit -m "wrong message"&lt;/p&gt;

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

&lt;p&gt;&lt;em&gt;you see the wrong commit message, now fix we will fix this&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;git commit --amend -m "right commit message"&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Now, you can see right commit message from which you have replaced, basically, it is a new commit, as you can see a new hash code for this commit message. &lt;em&gt;It changes git history, it is a bad practice.&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  4. You accidentally added a file which should be not committed
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Let try this,&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;touch not-to-be-commit.text&lt;/p&gt;

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

&lt;p&gt;git add not-to-be-commit.text&lt;/p&gt;

&lt;p&gt;git commit --amend &lt;br&gt;
&lt;em&gt;lets write :wq&lt;/em&gt;&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;and boom it disappears &lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  5. When you commit an in the wrong branch
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;git branch &lt;br&gt;
&lt;em&gt;there are two branches&lt;/em&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;master &lt;/li&gt;
&lt;li&gt;dev&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;We committed in the &lt;em&gt;master branch&lt;/em&gt; and move that commit in dev, Also we will be returning the master in the same status it was before this commit. The Answer is &lt;strong&gt;cherry-pick&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Cherry-pick doesn't delete any commit, it creates a new commit based on dependent commit.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let’s implement it&lt;/strong&gt; &lt;/p&gt;

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

&lt;p&gt;&lt;em&gt;Pick the hash which you want to cherry-pick and copy it&lt;/em&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;git checkout dev &lt;/p&gt;

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

&lt;p&gt;&lt;em&gt;You will see only a commit.&lt;/em&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;git cherry-pick --copied hash--&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You brought the commit in the &lt;em&gt;dev branch&lt;/em&gt;, however, it will not delete that commit from the &lt;em&gt;master branch&lt;/em&gt;. to answer this we have &lt;strong&gt;git reset&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;There are three types of git reset:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;git reset soft&lt;/li&gt;
&lt;li&gt;git reset mix&lt;/li&gt;
&lt;li&gt;git reset hard &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Let understand this with examples&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Git Reset Soft&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;git checkout master &lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;copy the hash which one you want to have last change&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;git reset --soft --copied hash--&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;You can see you no longer have that commit, which is good that we don't want it longer. &lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Now, you can see that there are some files in the stage area, by this command, you will not lose the work.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;Git Mix &lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;git reset -copied hash-&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;You can see you no longer have that commit, which is good that we don't want it longer.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Now, you can see that there are some files in the un-stage area, it’s on you, whatever you want to do- can add changes or delete*&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Git Hard &lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;git reset --hard -copied hashcode-&lt;/p&gt;

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

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

&lt;p&gt;&lt;em&gt;Boom!! Nothing is left and you are on your previous commit. New changes totally deleted!!&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Bonus: You want to get rid of the leftover- untracked file
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;git clean -df &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;d- directory &lt;/li&gt;
&lt;li&gt;f-files &lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;#### 6. When you want to track what you have done &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;git reflog&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  7. What if mistakenly run git hard and badly want the code back
&lt;/h4&gt;

&lt;blockquote&gt;
&lt;p&gt;git reflog&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;grab and copy the hash before the reset&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;git checkout -copied hash-&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;You are in the copied hash, &lt;em&gt;remember everything is hash in git (branch,commit and anything)&lt;/em&gt;, run git log in this hash&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;You clearly can see there are the commit we have reset earlier. &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;git branch backup &lt;/p&gt;

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

&lt;p&gt;git checkout master &lt;/p&gt;

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

&lt;p&gt;git checkout backup &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Isn't reflog a lifesaver?&lt;/strong&gt; &lt;/p&gt;

&lt;h4&gt;
  
  
  8. You wanna undo the commit but other people pull that changes
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;git revert&lt;/strong&gt;- &lt;em&gt;Git revert not delete or modify any commit, it simply creates a new commit top of those that completely undo the changes, so that history remains intact.&lt;/em&gt;&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;copy the hash which you want to revert &lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;git revert -copied hash-&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Write- :wq&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;&lt;em&gt;You can see there three commits- two are untouched and we have new commit with revert. if you see the file it undid the previous changes. To see these changes run diff command-&lt;/em&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;git diff -old copied hash- -reverted has(new commit)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  Remember, I said everything(branch, commit) in the git has hashcode
&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Lets, try this- we have three branches. You already know you have git in this directory by writing a command **git init&lt;/em&gt;&lt;em&gt;. Now, we will be doing print the hashcodes these branches. Try and run following commands&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;ls -al .git &lt;br&gt;
ls -la .git/refs &lt;br&gt;
ls -la .git/refs/heads&lt;br&gt;
cat .git/refs/heads/master&lt;br&gt;
cat .git/refs/heads/dev&lt;br&gt;
cat .git/refs/heads/backup &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;All these branches have different hashcodes&lt;/strong&gt;  &lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>devops</category>
      <category>linux</category>
    </item>
  </channel>
</rss>
