DEV Community

Abhinav Pandey
Abhinav Pandey

Posted on

Git Tip: Keeping an eye on the source repository

Why do I need to check out a source repository alongside my forked repository?

  • It helps you to compare the source code of the forked repository with the source code of the source repository.
  • It also helps you to see the changes made in the source repository.

Checking out the source repository

Step 1:
Open a Git Bash terminal.

Step 2:
Change directory to the directory where you have cloned the repository.

Step 3:
Check out the source branch.
Command syntax:

git remote add repo_name url_of_source_repository
Enter fullscreen mode Exit fullscreen mode

Runnning the command will add a remote repository named "repo_name" to the local repository.

Step 4:
Fetch the source branch.
Command syntax:

git fetch repo_name master 
Enter fullscreen mode Exit fullscreen mode

Runnning the command will fetch the master branch from the remote repository.

Comparing the two repositories

To compare the two repositories, you can use the following command:

git diff --stat origin/master repo_name/master
Enter fullscreen mode Exit fullscreen mode

The option --stat shows the number of added, deleted, and modified lines and not the actual content of the files. Don't use --stat if you want to see the actual content of the files.

Checking latest commits in the source repository

To see the latest commits in the source repository, you can use the following command:

git log [--oneline] [--graph] [--after=date] [--before=date] [--author=author] repo_name/master
Enter fullscreen mode Exit fullscreen mode

The option --oneline shows the commit message.
The option --graph is used to show the commit graph.
The option --after=date shows the commits after the date.
The option --before=date shows the commits before the date.
The option --author=author shows the commits made by the author.

There can be many more options to filter the commits. Check the Git log documentation for more information.


Thank you for reading! If you want to connect with me, you can find me on Twitter @abh1navv

Top comments (0)