Git Commands that can come in handy

You may be using Git for a long time or new to it. But, today I am going to introduce you to Git Log and Git Remote commands which might come very useful in your day to day interaction with the Git and can make your life pretty simple.

But first, you need to know the difference between Git and Github.

Git is Version Control System.

GitHub is a web-based service for version control using Git.

In easy words…

Git helps us to keep track of our files and any changes made to those files on our local machine.

Github is a website that contains source code in different repositories managed through Git

Alright now, let’s get started with Git Log

Git Log

Shows the commit logs.

Functions

  • It allows us to keep track of our works.
  • This command helps give context and history for a repository.
  • It let users customize the formatting of each commit output of the log.
  • It also lets users filter commits in the log output.

Let us explore some options that can be helpful with Git Log command:

Draws a text-based graphical representation of the commit history on the left-hand side of the output.

git log --graph

Here is an example of the log output with –graph keyword.

(The output is a big list, not just five commits) As shown in the above image, the “git log –graph” retrieved the commit history on the branch (issue-667) of the filer project.
(The list continues) As shown in the above image, the “–graph” shows you previous merge represented by a different color for each branch.

Link to view my pull request. Also, check out my previous post to know more.

The standard “git log” command isn’t very terminal friendly as it displays lots of text. So, if you want to view commit history with only commit message then, oneline can be very convenient.

As shown in the above image, with “–online” shows the commit history with just commit message.

To filter commits by their commit message


As shown in the above image, with “–grep” shows only those commits which include “fs.readdir.spec.js” in their commit message.

Click on this link to know other options of Git Log.

Git Remote

This Git command is used to manage your Central servers for hosting your git repositories.

Function

  • It lets you create, view, and delete connections to other repositories.
  • This command is also responsible for syncing change.
  • The git remote command is essentially an interface for managing a list of remote entries that are stored in the repository’s ./.git/config file.
Using git remote to connect other repositories

For example, the above diagram shows two remote connections from your repo into the central repo and another developer’s repo. Instead of referencing them by their full URLs, you can pass the origin and john shortcuts to other Git commands. (Source)
git remote

This command shows the list of all remote connections you have to other repositories.

To add a connection to John’s repo

git remote add john http://dev.example.com/john.git

To remove John’s connection

git remote rm john

It has only one option i.e.

git remote -v

This command shows the list of all remote connections you have to other repositories with the URL of each remote connection.

Sample output(Source)

git remote -v
origin  git@bitbucket.com:origin_user/reponame.git (fetch)
origin  git@bitbucket.com:origin_user/reponame.git (push)
upstream  https://bitbucket.com/upstream_user/reponame.git (fetch)
upstream  https://bitbucket.com/upstream_user/reponame.git (push)
other_users_repo  https://bitbucket.com/other_users_repo/reponame  (fetch)
other_users_repo  https://bitbucket.com/other_users_repo/reponame  (push)

Official Documentation links

Git Log

Git Remote

Some Cool Videos

Check out this video to learn some cool tricks with git-log

This is the best video if you want to become master of Git remote

Advertisements

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