“Git” good!

Akbar Novial
bisaGo2020
Published in
5 min readOct 8, 2020
source: unsplash.com

In this day and age where technology has dominated our everyday lives and has rapid changes, there must be some sort of way for developers to store all of the things needed without overwriting each other’s changes. Furthermore, We would need something that enables the developers to work together. That’s where Git comes into play.

What is Git?

Git is the most popular version control system in the world that records the changes made to a file and stores them in a repository. With Git, developers can see what changes are made, who made the changes, when were the changes made, and why are the changes made.

How can we “Git” good?

We can start by learning the basic commands needed to operate Git. These are the common commands used by developers:

  1. git init is the first thing to do when starting out with a new repository, you only need to do this once. By using this command, a hidden sub-folder will be made which allows the tracking of the directory.
  2. git clone creates a copy of the remote repository into a new directory locally by simply writing git clone [url].
  3. git pull can get the latest version of a repository which will make changes to the repository on the local computer.
  4. git add marks the changes that are going to be included in the next commit.
  5. git commit saves the changes to the local repository.
  6. git push updates the remote repository from the changes made in the local repository.
  7. git merge combines the changes made from different branches into one particular branch.
  8. git rebase is another way of integrating changes from one branch to another. It is also known as an alternative to git merge. The difference is, git rebase rewrites the commit history in order to create a straight, linear succession of commits. I’ve only used git rebase when I worked on my own portfolio website. I would rebase with the master after finishing any additional features. This makes my project history to be cleaner than using git merge. The reason why I don’t use git rebase in my PPL project is that I don’t want to raise any confusion with my team members regarding the commit history, just in case. I’d rather use it for my personal projects.
  9. git revert is used to undo an existing commit. This, however, does not delete any data, it instead creates new changes with the opposite effect. Thus, undoing the old commit. To use git revert, you need to specify the parent number and commit id to overwrite it.
  10. git stash is used to store your uncommitted local changes temporarily, enabling you to work on something else and come back later on to re-apply them. Some situations require
  11. git remotehelps to manage connections to remote repositories. It allows us to show which remotes are connected and add or remove existing remotes.
  12. git checkout is used to switch branches so we can start working in a different branch. git checkout can also be used to restore a historic version of a file, while keeping the rest of the project untouched.
  13. git branch can be used to show the branches being worked on locally, adding a new branch, or deleting a branch.
  14. git reset can be used to undo the commits up to the last commit of a branch. When using git reset, you also need to specify which branch you want to reset to. An example of when I used git reset is when I used the wrong commit message. As the commit message is quite important and helps identify what changes you made, using git reset helped me to correct it. I reset my branch to the last pushed commit and redo the commit message, and put in the correct one.

Git Reset or Git Revert?

This can be a good question because the purposes of git resetand git revert are similar as they both undo the commits.

In my case, I usually use git reset when I want to undo all of the changes I’ve made locally and to undo a commit that has not been pushed yet. This also makes the working tree cleaner. Furthermore, git reset has a couple of options you could use, git reset --soft and git reset --hard . git reset --soft can be used when you want to undo a commit but still want to keep the changes made. It could also be used when you want to combine a series of commits by undoing the series of commits and then recommitting all of the changes as one. Whereas git reset --hard can be used when you want to undo all of the changes we’ve made, and undo a commit that we don’t want the changes to be saved.

For git revert I would use it when I push a commit that I didn't mean to push, either because the changes are incorrect, wrong commit, or others. Using git revert in this case, is preferable because it will simply undo all of the changes that have been made before.

Git Flow

Git comes with a branching model or pattern that helps the team track the changes made in the project, this is called Git Flow. Moreover, Git Flow makes the master branch much cleaner. Earlier, I mentioned that there are branches in Git. My team and I are currently working on a project for bisaGo, some of the branches that are essential to use when working on a project are as below, accompanied by the rules we have to follow:

  • The master branch is the main branch, it is used to store the source code that is ready to be deployed and used by a user. You can only merge to this branch after having an approval from the product owner or lecturer during the sprint review.
  • The staging branch is the development branch that contains the code before going to production.
  • The user story branch stores the source code of a user. The branches will be named accordingly to their developer(member).
  • The hotfix branch is the branch taken from the master branch if there is a bug or error that needs to be fixed. Once the bug or error is fixed, it will be merged into the master branch.
  • The coldfix branch is the branch that is used to roll back the changes from all user story branches. This usually happens after a sprint review when the product owner is not satisfied with one or more user stories that have been developed.

Now that you’ve read this article, hopefully, you will be able to apply your knowledge of git and start using it in your projects. Using it will definitely give you lots of benefits and will help in your development as a developer.

References:

--

--