What a ‘git’ty day!

What a ‘git’ty day!

Hello friends! The blogpost’s title may seem strange to you but believe me I have felt this many times for two days. The one thing that I have realised in these days that if someone says “I know git.”, he is stupid and I am no exception. I only knew basic four git commands(init, add, commit, push) till yesterday though, I thought I know it.

I remember the days when every professional I used to know git and how much they used to praise it. I never realised what in the world these people find so cheerful in this command line tool. One day, I also installed git and all its fancy Visual interfaces. I read a couple of tutorials and misinterpreted, the four basic commands are the heart and soul of VCS like git. But today, when it came to use git in real programming projects, man! so exciting and challenging at the same time. I started feeling like being in a Aerodynamics class where I only knew terms like Force, Momentum, Velocity etc. I learned a lot in this time span and not only about git but also about open source projects and real programming projects’ workflow. I talked to fellow developers on the project when I was stuck and they were really very kind and supportive. One of the developer is younger than me(2 years, I guess) but he is way ahead of me and that motivated me.

An overview of what I learnt today-

  • Linus Torvald is a Legend.
  • Forking a git repo – Forking a git repository is like making a exact copy of whole project as a repository. If you fork a git repo you also get total history of all the commits being made.
  • Pull request – When someone starts contributing to a open-source project, he/she clones the base repository and then start developing, removing bugs, adding features on top of it. Suppose I implement a new feature in a chatting app in my local repository and want that feature to be added to base repository then I can make a Pull request with all my applied changes. Then the people who maintains the code and proper workflow of the development decides if the request should be accepted or not. If the Pull request gets accepted, they merge your updates to the base repository and you can pat yourself on the back.
  • git commit command – I knew this command(at least I thought so). git commit is used to record the changes that you make in a repository with a message to make it easy to identify the changes. This command is a boon for software developers who work on huge projects but this command can be a pain in the neck if used recklessly. Today, this command made me to suffer a lot. I committed wrong set of files and not just couple of times, I did it 6-8 times. I was totally blank on how to resolve that. Then one of the collaborators helped me and told me to use rebase command.

    git commit -m “your_message_for_the_commit”

  • git rebase command – This is the command which saved my day. When I was struggling through useless commits, I used this command to remove them. By this command you can edit, update, squash(remove) a git commit. You can also merge two or more commits using this command. The below command will open a configured text editor and list last two commits(replace 2 from the command with n to get last n commits). Then you can update those commits accordingly.

    git rebase -i HEAD~2

  • Branching in git – When you start developing a new feature of an existing project, make sure you make a separate branch than the master branch. Master branch is the main stream of development towards our end result as a whole software. So make sure you not mess with this master branch. Even if you mess up something, there are a lot of ways to get out of the trouble.
  • git checkout command – Using git you can make any number of branches and to select a particular branch, you use git checkout command. Replace the ‘branch_name’ in below command with your desired branch name. You can also use this command to see the changes committed at the time of a particular commit. Just place the commit id instead of branch name to list all the changes.

    git checkout ‘branch_name’

  • git branch – This command lists all the branches present in the repository. Then you can checkout a particular branch from the list.
  • git diff – When you start making changes between two commits, there may be a case when a particular change in code breaks the whole software. Searching for the culprit for the crash manually can take you forever in a very big project. To make it super easy you can use git diff command to get the list of changes you made to the files of the project between those two commits. You specify a particular commit by using its commit id.

    git diff 5asdfjasd393… eff342125…..

  • git merge – Let’s say you start working on a separate branch from the master branch to add some cool features to the app. Once you implement those features you think of testing those features and after passing all standards you think of adding those features to the main project. So in this case, instead of implementing those features again to the master branch, you can merge the branch with additional features with the master branch and by doing this you will save yourself a lot of time and efforts by avoiding writing redundant code.

There are also a dozen of other things that I learnt about open-source and git today. I will keep updating you all with new things that I will learn.

-Abhay Maniyar



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s