Author: Sahil Suri

git add command explained with examples

Introduction In our last article, we explained how to add content to a local git repository. There we used the git add command to add the README.md file to the repository we initialized with git. In this article, we will talk about the git add command in greater detail and will also demonstrate some common options used with the git add command with examples. What does the ‘git add’ command really do? This command updates the index using the current content found in the working tree, to prepare the content staged for the next commit.  A “working tree” consist of files in the repository that you are currently working on. An “index” is the staging area where new commits are prepared. It acts as the interface between a repository and a working tree. The index holds a snapshot of the content of the working tree, and it is this snapshot that is taken as the contents of the next commit.  Thus after making any changes to the working directory, and before running the commit command, you must use the add command to add any new or modified files to the index. The git add command can be performed multiple times before a commit.  It only adds the content of the specified file(s) at the time the add command is run; if you want subsequent changes included in the next...

Read More

How to add content to a local git repository in Linux?

Introduction In our previous article on the git version control system, we explained step by step how to create a local git repository. In this article, we will demonstrate how to add content to the empty git repository we created earlier in the previous article. We will also explain the steps that are involved in the process of saving new content to git and will also define related terminology along the way. Before we add content to our repository let us first understand the output of the ‘git status’ command where we ended our last article. [sahil@linuxnix my_first_repo]$ git status # On branch master # # Initial commit # nothing to commit (create/copy files and use "git add" to track) Understanding the terms commit and master: The first line of the output of the ‘git status’ command tells us that we are on the branch master and at the initial commit. So what does this mean? When we save a file in a git repository, git refers to this process as a ‘commit’ operation. Here is a more detailed definition of ‘commit’ in accordance with git terminology: A commit or revision is an individual change to a file or a set of files. In case of git creating new files within a repository would also be considered as a commit operation. A git commit is just like saving a...

Read More

6 GIT diff command examples

Introduction to git diff command In our last article on working with the git distributed version control system, we explained how to use the git log command to track changes and updates made to our git repository. In this article, we will see how we could check what changes were made to the files or more precisely the differences between the committed or saved versions of a file in the repository. For viewing the actual differences between the different versions of a record, we will use the git log command and the git diff command. To understand the differences between the current state of the file in the repository compared to their last known state, we use the git diff command. A git diff command can be useful for comparing Show local changes Show difference between stagged and remote repo Show difference between two commits Show difference between two files Show difference between two branches Show difference between two tags Example 1: View difference between the last commit and current version of a file Continuing to use the git repository at location /home/sahil/git/my_first_repo, I’ve now added a line to the file test.txt in this repository. [sahil@linuxnix my_first_repo]$ cat test.txt This is a test file! Added another line to test file [sahil@linuxnix my_first_repo]$ echo "Adding a third line to test file" >> test.txt [sahil@linuxnix my_first_repo]$ cat test.txt This is a test file!...

Read More

Over 16,000 readers, Get fresh content from “The Linux juggernaut”

Email Subscribe

ABOUT ME..!

My photo
My name is Surendra Kumar Anne. I hail from Vijayawada which is cultural capital of south Indian state of Andhra Pradesh. I am a Linux evangelist who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. At present I work at Bank of America as Sr. Analyst Systems and Administration. You can contact me at surendra (@) linuxnix dot com.