My encounter with git!

Parth Pandya
3 min readJun 1, 2020
Logo (Git)

In times gone by, I was working with Git using command-line interface on my Linux machine. Actually, it was an open-source contribution to an Open-source organisation — “The ns-3 network simulator project” which I was a part of. So, the stuff with which I messed up was Git-Branch. Well that’s not alone, as I faced severe conflicts with this particular mess lead me to learn many new features of Git as a command line version control which is meant for tracking changes in source code during software development.

Let me tell you all I was working on Gitlab, what I was doing that night! I solved one issue of that organisation (ns-3) in my local machine & then wanted to get that be pushed to my remote workspace. So, ultimately I have to do a Merge request to ns-3 after pushing the changes to my forked repository. But, I wasn’t able to see the “green-button” through which I can do a MR simply. So, I consulted my mentor “Tom Henderson”, we discussed about this for much time and in the end of the conversation he asked me of the project-id of the repository I was working with, which later lead to know that it wasn’t matching at all with the official ns-3’s repository, and that was a huge blunder. Because long ago, I had cloned a repository of that type irresponsibly. So, in the conversation what we discussed is presented to you in a following way :

  • To view all your Remote references such as — remote name, including branches, tags etc; use below command:
$ git remote -v
  • To view which branch git is tracking upon, use below command :
$ git branch -vvv
  • To switch between branches, use below command:
$ git checkout
  • To fetch all the changes from the remote repository and store it in a separate branch in your local repository, use below command:
$ git fetch

this will reflect the changes in your corresponding branches by merging.

  • To pull changes from a particular remote & particular branch, use below command:
$ git pull

if we see the above two commands, we can conclude as $ git pull = $ git fetch + $ git merge.

  • To create a new feature branch locally, use below command :
$ git checkout -b
  • To check and list out all the branches your repository have, use below command:
$ git branch -a
  • To apply a patch file (more specifically, a $ git diff file ), use below command:
$ git am <the patch file> or $ git apply <the patch file>

All the above were discussed by us, then after some months I came to know the importance of having different branches in our repository — it generally allows each developer to branch out from the original code base and isolate their work from others. It also helps Git to easily merge versions later on.

So, long story short I’ll end up saying one more incident when mentor “Peter Barnes” and I were working on an issue. I proposed a solution which I pushed it on my remote repository but in the same branch on which I still had some pending merge requests. So, that created conflicts! HAHA! Then, mentor told me about using branches — A separate branch to be made from master branch for the latest work I’ve proposed.

In the end, I’ll be glad to share one GIT-TIP here :

When you contribute to any git repository from your local machine, it’s generally you use some code editor. So, when your work from local to remote get pushed, it will show you the number of insertions to it’s max — like if you had changed over some 100 lines and previously it had some 1300 lines, you’ll be viewed with +1400 insertions and most probably (not sure) around -1200 deletions. In such cases when you want to see the actual changed stuff i.e exact number of insertions and deletions made by you, so in such cases you’ll need to change the git line-endings by using below command :

$ git config --global core.autocrlf true

That’s all from my side. However, Git comes with some more handy things which really makes the version control easier.

Thankyou.

--

--