Git 101 : Github Basics Pt2
Category : DevOps Tag : 101series shellscript
Jan. 11, 2021, 9:09 p.m.

Short Description :
This is pt 2 of github 101, focusing on branch and other miscellaneous but helpfull operations
source : datak

<p style="font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; color: rgb(0, 0, 0);">In&nbsp;<a href="http://datak.biz/blog/detail/7/" target="_blank">git 101 pt1</a>, we've talked about how to set remote repository at github and how to upload initial existing data in our local repository, and update remote repo based on changes we review in git CLI. In pt2, we will talk about how to create branch and additional helpful commands</p><h3 style="font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; color: rgb(0, 0, 0);">STEP3. Create branch &amp; merge</h3><p>Branch is another types of version control. If there are some projection on the application which we might be not sure if we should add or how we can make it. In that case, branch concept is helpful and is not messing up your original version called "master(or main)". You can create branch by</p><pre>git branch &lt;your branch name&gt;</pre><p>then you will see current branch list by&nbsp;</p><pre>git branch</pre><p>if you would like to change branch, type</p><pre>git checkout &lt;your branch name&gt;</pre><p>Note, any un-staged changes are not reflecting when you create new branch.</p><p>Once you are ready for the update in github remote repo for the branch,</p><pre>git add . git commit -m '&lt;your change explanation here&gt;' git push origin &lt;your branch name&gt;</pre><p>At your local environment, if you checkout and change branch, your will automatically see different revision on the application.</p><p><br></p><p>Now, if you are ok for your side branch and would like to reflect into master branch, you need to send merge request(pull request) for developers for the project.</p><p><img src="/media/django-summernote/2021-01-12/92b13223-03d5-4ca5-a9c0-e048bf8dca57.png" style="width: 100%;"><br></p><p>Then for those who are reviewer on the change(ie. approver) is supposed to review the change and accept the merge(pull) request. Github provide was-is (similar to git diff) in the github browser and merge will be made once each approver accept the request.</p><p>If your merge request is made in github remote repo, you need to reflect the changes in your local.</p><pre>git pull origin master</pre><p>If you don't need the branch, then delete by</p><pre>git branch -d &lt;your branch name&gt;</pre><p><br></p><h3 style="font-family: &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; color: rgb(0, 0, 0);">STEP4. Miscellaneous</h3><p>Here, we will introduce few practical git CLI commands (at least I've been frequently using in devops)</p><p><br></p><h4>Git ignore</h4><p>While we are using cloud environment, we tend to have different local repo (one in local other in cloud like digital ocean droplet). For some web framing library such as django and react, they automatically update their cache and this is nothing but our coding, so we would like to ignore the file. In that case, we can use git ignore CLI. git ignore file is automatically created at right below of repository. You can open by</p><pre>cd &lt;your repo&gt; ls -a #to show .gitignore file vim .gitignore</pre><p>Then in .gitignore file, put any file which we would like not to monitor by git so git does not have to report these changes</p><p><br></p><h4>Force Reflect</h4><p>Having said that we can use git ignore to manage excluding unnecessary changes through git, sometimes we would like to just overwrite. In that case, do followings&nbsp;</p><pre>git checkout &lt;branch that you would like to overwrite&gt; git fetch git reset --hard origin/master</pre><p>In the case above we are overwriting with master in remote repo to local branch we select.</p><p><br></p><h4>Reconnect local and remote repository</h4><p>In some cases, we've started a certain application project and eventually we will face that we need to change application name. Then we would like to repo name at remote and local. In local, most of web framing can freely rename such as django and react(create-react-app) by</p><pre>cd &lt;your current local repo&gt; mv &lt;your current local repo name&gt; &lt;your new local repo</pre><p>We can also quickly change name in remote repo in github browser, going to setting at top nav bar.</p><p>One thing we need to do after that is we need to re-connect to new URL as renameing in remote repo changes URL which local repo connects. You can check your current connection by</p><pre>git remote -v</pre><p>In order to change the connection, go to github page and get current connection URL then put</p><pre>git remote set-url origin &lt;your new remote repo URL copied from github browser&gt;</pre><p>In case you would like to reconnect to heroku git, change from origin to heroku</p><pre style="line-height: 1.42857;">git remote set-url heroku &lt;your new remote repo URL copied from github browser&gt;</pre><p><br></p><p><br></p>


<< Back to Blog Posts
Back to Home

Related Posts

Github Gist and Bl.ocks
Dec 11 2020
Explain how to use github gist and quick rendering d3.js from the page
Git 101 : Github Basics Pt1
Nov 28 2020
Basic commands for git operations, such as add/commit to repo, change/merge branch etc.



© DATAK 2024