<div dir="ltr">Hi All,<div><br></div><div>I attended the DevOps meetup held at Addteq in Princeton, NJ on 11 February 2016. The talk was on &quot;Practical Git Tips and Tricks&quot;. </div><div><br></div><div>The meetup was held with equal emphasis on a talk with demonstration and networking. The demonstration&#39;s main focus was going through different git commands that were compiled together keeping day to day scenarios and use cases in mind. The following git commands were explained:</div><div><br></div><div>1. git stash<br></div><div>This command is used when you want to save the changes done in your local directory and start again with a clean working directory. The current copy then points to the latest HEAD commit.<br></div><div><br></div><div>2. git remote set-url origin &lt;repo-of-your-git-url&gt;</div><div>This command is used to change the Git URL from HTTPS to SSH or to relocate/point your working directory to another Git URL.</div><div><br></div><div>3. git remote set-url [--push] &lt;name&gt; &lt;new-url&gt; [&lt;old-url&gt;]<br></div><div>This command is especially useful when you have Git mirroring setup. You can set the pull URL to the master one and the push URL to the mirror node.</div><div><br></div><div>4. git reset --soft origin/master</div><div>This command will rollback your branch to the same commit as origin/master and saves all your commits to staging. </div><div>There are three modes of reset:</div><div>-soft</div><div>-mixed</div><div>-hard</div><div><br></div><div>5. To delete an incorrect commit in Git, you can use any of the following:</div><div>git reset --hard &lt;commit-id&gt; where commit-id is the id of a specific commit.</div><div><br></div><div>If the wrong commit you made is already pushed then you will have to do a force push. Usually force push is disabled for users as that might have adverse effects on the repository if someone does a force push to the master branch by mistake.</div><div>git push origin HEAD --force</div><div><br></div><div>However, if someone has already pulled from the incorrect commit and push you made it is better to just start off with a new branch.</div><div><br></div><div>6. Undoing a Git merge commit</div><div>-Rewind your branch to the point you want to unmerge (git reset --hard &lt;commit&gt;)</div><div>-Remerge any lines if needed (git merge &lt;branch-name&gt;)</div><div>-Once you rewind and unmerge you can work on the newly unmerged line and commit at a later point or ignore it.</div><div><br></div><div>7. Dealing with merge conflicts</div><div>-Git conflicts occur only on the local copy and not on the remote server.</div><div>-Run the &quot;git status&quot; command to find where the conflict is.</div><div>-To accept local/our copy: git checkout --ours path/&lt;file-name&gt;</div><div>-To accept their/remote copy: git checkout --theirs path/&lt;file-name&gt;</div><div><br></div><div>8. Appending to commit messages in Git</div><div>git commit --amend</div><div>You can only modify the most recent commit using the above command. </div><div>But if the commit is already pushed then you need to use: git push --force origin &lt;branch-name&gt;. Again, involving a force push anytime is not a good practice.</div><div><br></div><div>9. Delete a Git branch both locally and remotely</div><div>-Local: git branch -D &lt;branch-name&gt;</div><div>-Remote: git push origin --delete &lt;branch-name&gt;</div><div><br></div><div>The talk also explained git submodules briefly.</div><div>-It helps split large projects into smaller pieces.</div><div>-It allows you to keep a Git repository inside your current Git repository.</div><div><br></div><div>I chose this event as I use and am interested in learning more about Git and it&#39;s variations. </div><div><br></div><div>Even though I use it a lot of times these tips and commands will help me improve my skills and especially resolve merge conflicts which usually are difficult to resolve if the right commands are not used at the right time. I understood a lot of tips to rollback yet stash the local changes so that you don&#39;t lose those.</div><div><br></div><div>Overall the event was a good learning experience and more than just facts I got to learn actual commands and see a live demonstration of how each one works which I think is definitely is a huge plus for any beginner. </div><div><div><br></div><div class="gmail_signature"><div dir="ltr">Thanks,<div>Sneha</div></div></div>
</div></div>