Git

Should We Use Squash and Merge Option?

When we merge PR into the base branch, we have an option to do Squash and Merge. My preference is to use it all the time. Let’s talk about why this is the case. First of all, what do we want from our commit history? We want to have a …

Git

How to Add Private Key to SSH Agent with Git Bash

The ssh-agent provide a secure way to hold the private keys of remote server. It is a program that runs in the background. While you are logged into the system, it is storing your keys in memory. If you are using a SSH key with Git, the ssh-agent is used …

Git

Alternative to Squash Commit

If we have three commits that we want to squash as below, we can simply use git reset, add and commit to squash those changes into one commit. commit edba792d5ea2aec40f413a23bf539fa25270da65 Author: mdh Date: Thu Feb 27 09:00:16 2020 +1100 Updated model3 commit 8ea10ef480c8cde59b2d78ae0fbe5367f877e59d Author: mdh Date: Thu Feb 27 08:59:51 …

Git

Find a Remote Branch and Fetch it to Local with Git

git branch -r can list all the remote branch. In any large scale application code base, you are likely to get heaps of branch names. By piping grep, we can narrow down the remote branch git branch -r | grep MDH-112 This gives us a fewer options. origin/MDH-112-dev-branch origin/MDH-112-experiment origin/MDH-112-delete …

Git

How to Roll Back Merge Commit on Master Branch with Git

When rolling back a merge commit, I prefer to do it with git revert because it creates a new commit. Using -m 1 indicates that this is a merge and we want to roll back to the parent commit on the master branch. -m 2 is used to specify the …

Git

How to Rename a Branch with Git

Renaming a local branch is easy by using git branch command option -m. For the remote branch, we can create a new remote branch by pushing the renamed branch and then deleting the old branch. Here are the steps. (1) checkout git checkout old-branch-name (2) rename git branch -m new-branch-name …

Git

How to Rebase with Git

Here are the steps to rebase from master with Git. After doing this a few times, rebase is not so scary any more. Rebase vs Merge can be contentious. Generally speaking, I prefer to rebase because it creates a cleaner history. (1) Make sure to be in the feature branch …

Git

Difference Between Git Reset and Revert

Git reset and revert are similar, but understanding the difference is important. They can both roll back the change you made. The differnce is that reset moves the pointer back to the commit you specify, while revert creates another commit at the end of the chain to cancel the change. …

Infrastructure

Create Custom Python Module and Distribute with Git

When we create a custom Python module, we can distribute it through a Git repository. By using a private repo, you can keep your module private and use it in your deployment pipeline by calling pip install from the private repo. Pretty cool trick. In this example, I created a …

Infrastructure

How to Set up Dual-Authentication to GitHub and AWS CodeCommit

Both GitHub and AWS CodeCommit are used to version-control your source code. I use GitHub to share my code with the wider community and CodeCommit for production code for AWS. You may use other source control systems like BitBucket. Whatever the choice you make, it is convenient to set up …