<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Mykel's World]]></title><description><![CDATA[A self-taught programmer.  I love to share what I learned.]]></description><link>https://mykelbarua.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 10 Oct 2026 18:32:14 GMT</lastBuildDate><atom:link href="https://mykelbarua.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Learn Git basic, merge conflict, and push local to remote.]]></title><description><![CDATA[Hey there,
I'm Mykel. I'm a self-taught programmer. I love to share what I leaned.
This is my first write-up. I learned git recently and thought share it with you.
Git is the most used tool by developers. You can't help yourself to use it.
Here we do...]]></description><link>https://mykelbarua.hashnode.dev/learn-git-basic-merge-conflict-and-push-local-to-remote</link><guid isPermaLink="true">https://mykelbarua.hashnode.dev/learn-git-basic-merge-conflict-and-push-local-to-remote</guid><category><![CDATA[GitHub]]></category><category><![CDATA[Git]]></category><category><![CDATA[GitLab]]></category><dc:creator><![CDATA[Mykel Barua👋]]></dc:creator><pubDate>Mon, 30 Aug 2021 17:55:54 GMT</pubDate><content:encoded><![CDATA[<p>Hey there,</p>
<p>I'm Mykel. I'm a self-taught programmer. I love to share what I leaned.
This is my first write-up. I learned git recently and thought share it with you.</p>
<p>Git is the most used tool by developers. You can't help yourself to use it.
Here we don't talk much about what is git. If you don't know about git, simply google it.
I assume that you know about git. You want to learn git or maybe you know a bit and want to learn more then this article is right for you. I start from a stretch. </p>
<p>First download git from <a target="_blank" href="https://git-scm.com/downloads">here</a> . Download the file according to your OS and install it simply. It's so easy, trust me.
Now create a folder and open the terminal in it. This is the right time to start learning git. To initiate git run the command down there.</p>
<p><strong>Git Initial:</strong></p>
<pre><code>git <span class="hljs-keyword">init</span>
</code></pre><p>Congrats, you have done very well. Let's proceed next steps.
Now create some files in the folder. Use terminal or create visually. 
Let's think we have created one.txt and two.txt</p>
<p><strong>To know about changes or status about files:</strong></p>
<pre><code><span class="hljs-attribute">git</span> status
</code></pre><p>Notice your created files are red marked. It's because don't to stage them yet. The stage is a medium state. 
There are some commands to staging files. Here are them.</p>
<p><strong> To staging your changes:</strong></p>
<pre><code>git <span class="hljs-keyword">add</span> <span class="hljs-comment">--all</span>
</code></pre><p>or</p>
<pre><code>git <span class="hljs-keyword">add</span> -A
</code></pre><p>It's worked for all files and directories. Including forward and backward.</p>
<pre><code>git <span class="hljs-keyword">add</span> .
</code></pre><p>Dot (.) do stage in all files which have (.) or ext. This works like going only forward. For example, if you are the main branch, you add dot(.), it will staging all files including the subdirectories. But if you are a directory, then you add dot(.), it's just staged those files which are in this directory and subdirectory of it but not those which are in the main directory.</p>
<pre><code>git <span class="hljs-keyword">add</span> *
</code></pre><p>This command will stage every file except deleted. This command doesn't stage any deleted files.</p>
<p><strong>For a single file:</strong></p>
<pre><code>git <span class="hljs-keyword">add</span> fileName.ext
</code></pre><p><strong>Only for .txt files:</strong></p>
<pre><code><span class="hljs-attribute">git</span> add <span class="hljs-regexp">*.txt</span>
</code></pre><p><strong>Only for .js files:</strong></p>
<pre><code><span class="hljs-attribute">git</span> add <span class="hljs-regexp">*.js</span>
</code></pre><p>After staging files will be green marked.
Now you want to unstaged files and want to back in the working directory.</p>
<p><strong> To unstaged:</strong></p>
<pre><code>git <span class="hljs-keyword">reset</span>
</code></pre><p> After staging, commit your files and save them completely.</p>
<p><strong>To commit or save your changes:</strong></p>
<pre><code>git <span class="hljs-keyword">commit</span> -m "&lt;message&gt;"
</code></pre><p>After doing commit check git status. You see the working tree is clean, which means there is nothing to commit.</p>
<p><strong>To uncommit or back to the working directory:</strong></p>
<pre><code>git <span class="hljs-keyword">reset</span> <span class="hljs-keyword">HEAD</span>~
</code></pre><p><strong>Undo delete or reset changes with the hard file:</strong></p>
<pre><code>git <span class="hljs-keyword">reset</span> <span class="hljs-comment">--hard</span>
</code></pre><p>But this reset will also remove untracked files and directories.
Suppose your main directory is gitone(folder-name). Your this directory is now tracked. Now you created a new directory, for example, myFolder and three.txt in it. Now you deleted two.txt unconsciously and staged your changes. Then you notice your two.txt file is deleted and now you want to back this file. For this purpose, you use reset --hard. You definitely back your two.txt hard file but the newly-created directory myFolder and file three.txt will remove. Because the directory and file were untracked.</p>
<p><strong>Git Remove:</strong></p>
<pre><code>git rm <span class="hljs-tag">&lt;<span class="hljs-name">fileName.ext</span>&gt;</span>
</code></pre><p>The difference between manually delete and rm command is if you delete manually you have to add change using add command, but if use the rm command your hard file will be removed and change will be staged automatically.</p>
<p><strong>To remove file forcefully:</strong></p>
<pre><code>git rm <span class="hljs-tag">&lt;<span class="hljs-name">fileName.txt</span>&gt;</span> -f
</code></pre><p>Suppose your working tree is clean, nothing to add, and nothing to commit. Now edit a file like two.txt. and you don't add your changes yet. At this moment you want to remove your file two.txt with the rm command. But surprisingly you will see git doesn't let you remove the file. Do you know why? because you don't add and commit your file yet. So if you really want to remove your file and are fully aware that you want to get back the file later, you don't get the changes that you make now. To understand git that, use --f flag. Git will remove the file And understand that you know the consequences. </p>
<p><strong>To remove folder:</strong></p>
<pre><code><span class="hljs-attribute">git</span> rm -r folderName
</code></pre><p>It will remove files and subfolders in it.</p>
<p><strong>Branching:</strong></p>
<p>Now we are going to learn about branch. It's the most interesting topic about git. 
First We should know what is Branch?
Suppose you have done a project and deliver the project to the client. After few months your client wants to change in code or develop. Now can't touch your main code without fixing bug of new changes, right? Now, what are you do? copy the whole code in another folder then do changes? It's not sound good right! Here is the work of Branching. When you make a branch your branch will copy everything that you have in the main branch. Now see you have copy anything nor have to touch main code.</p>
<p>Now at first check, how many branches we have!</p>
<p><strong>Check branch:</strong></p>
<pre><code><span class="hljs-attribute">git</span> branch
</code></pre><p>You got only the main branch right. okay, let's create a new branch.</p>
<p><strong>Creating new branch:</strong></p>
<pre><code>git branch <span class="hljs-tag">&lt;<span class="hljs-name">branchName</span>&gt;</span>
</code></pre><p>Again check branch now. you see created a new branch with the main branch. Now it's time to switch to our new branch.</p>
<p><strong>Switching to branch:</strong></p>
<pre><code>git checkout <span class="hljs-tag">&lt;<span class="hljs-name">branchName</span>&gt;</span>
</code></pre><p>There is a shortcut for creating and switching in a branch with one line of command.</p>
<p><strong>Creating and switching in branch:</strong></p>
<pre><code>git checkout -b <span class="hljs-tag">&lt;<span class="hljs-name">branchName</span>&gt;</span>
</code></pre><p>You still don't get it fully! Okay, I understand. Let's make it easier for you. Now you are in your new branch, right? let's think its name is development. Now in the development branch, we will create a file. For example, four.txt. add and commit the file. Check git status. Your working tree is clean, right!</p>
<p>Now switch branch development to main.
Have you seen the four.txt file here? No, right! Now again switch to development. You see four.txt now. Hopefully, you got how branching works.</p>
<p><strong>Merging:</strong></p>
<p>We have a branch named development and that branch has some files. Now you are sure changes are ready for production or change are ready to merge with the main code/branch. Now switch to the main branch, if you have not yet. Then command,</p>
<p><strong>To merge:</strong></p>
<pre><code><span class="hljs-attribute">git</span> merge &lt;branchName&gt; -m <span class="hljs-string">"message"</span>
</code></pre><p>in our case, it will be like</p>
<pre><code><span class="hljs-attribute">git</span> merge development -m <span class="hljs-string">"merging on main with development"</span>
</code></pre><p>Now you can see all the files, you created in development branch merged in main branch.</p>
<p><strong>Merging conflict:</strong></p>
<p>Suppose your friend created a branch to change in some code. Let's say it staging. so now you are working on the development branch and your friend is working on staging. you and your friend change a common file. let's say it two.txt so you have changed something in two.txt and your friend too. But you both don't know about it. After changing you have added and committed. Now you think to merge your friend's branch staging with your branch.
What you see! Git saying he is failed to auto merge. Because he doesn't know who's changes should be kept. And if you open the file which git has conflict to merge, in our case two.txt, has shown where the conflict is occurred in the code. Now you DM your friend and discuss what change should keep. After solve the conflict add and commit the file. Then DM your friend to merge with your branch.</p>
<p><strong>Push Local to Remote:</strong></p>
<p>It's time to push our files local to cloud. There is some cloud storage to share code such as GitHub, BitBucket, and GitLab. Here we are going to use GitHub. It's free and awesome. First you have to sign up in GitHub, if you don't do that yet. Go to GitHub and Sign up.
I assume that you have sign up in GitHub and log in there. Now create a repository in GitHub and copy repository link.
Suppose you create a repository name as gitTest. So your repository link will be like - <em>https://github.com/your-user-name/gitTest.git</em> </p>
<p>Now back to your terminal. First, switch to the main branch, if you are already switched then it's good.
Set your remote origin to use the command.</p>
<p><strong>Set remote origin:</strong></p>
<pre><code>git remote <span class="hljs-keyword">add</span> origin &lt;repository url&gt;
</code></pre><p>Then push your code local to the cloud storage.</p>
<pre><code>git push -u origin <span class="hljs-tag">&lt;<span class="hljs-name">branchName</span>&gt;</span>
</code></pre><p>In our case,</p>
<pre><code>git <span class="hljs-keyword">push</span> -u origin main
</code></pre><p>A pop-up will appear and put your GitHub username and password.
Now refresh your GitHub repository tab. You see your all files are pushed to the cloud.
You notice the main branch has pushed only, other two branch doesn't. To push other branches also switch to those branches one by one and push.</p>
<p><strong>Remote to local:</strong></p>
<p>Still, we change our files in the local storage. Let's think you have changes some files in the cloud and you want to merge them in local too.
Use this command to fetch changes remote to local.</p>
<pre><code>git <span class="hljs-keyword">fetch</span>
</code></pre><p>If you check git status you see nothing is there. Also, check your hard files. Nothing has changed right. Actually, the fetch command just fetches the changes, not the hard file. For merging hard files also, you have to command one more.</p>
<pre><code><span class="hljs-attribute">git</span> merge
</code></pre><p>Now see hard file also change.</p>
<p>First, fetch and then merge, it's not cool right! Why not do it in one line. Here is it.</p>
<pre><code><span class="hljs-attribute">git</span> pull
</code></pre><p>This command will fetch and merge the data automatically.
Want to show your git commit history! simply command,</p>
<pre><code>git <span class="hljs-keyword">log</span>
</code></pre><p>You may want to clone other code repositories from the cloud storage. Here is the command for that.</p>
<p><strong>Clone git repository:</strong></p>
<pre><code>git clone <span class="hljs-tag">&lt;<span class="hljs-name">repository</span> <span class="hljs-attr">link</span>&gt;</span>
</code></pre><p>These are the basic things you should know to start work with git.</p>
<p>Happy coding!
Control your program version with git and share your code through GitHub.</p>
<p>I appreciate sharing your thoughts about this article. Wanna give some advice, I'm all free to hear. Find it useful please share it with your friends to learn what you learned.</p>
]]></content:encoded></item></channel></rss>