Git states

Broadly speaking, there are three states in which your files can be: modified, staged and committed. It is crucial to understand these terms, which will help in familiarizing yourself with the git environment

  1. Modified: This refers to the state when you have made changes to the file but you have not committed the changes yet.
  2. Staged: It means that you are ready to commit the changes you have made in your file, marked as modified.
  3. Committed: It indicates that the data is stored in your local database.

Starting a new project with git

Let’s Begin by Creating a Local Repository (Execute the command in a Cell) and simultaneously see how to “commit”, which is creating a snapshot of the entire state of the project at a moment. Github helps you create a remote repository.

Random trivia: Github has recently changed the name of “master” branch to “main” due to cultural sensitivity around slavery.

Git init


Initialised empty Git repository in D:/git_training/.git/

The Exclamation Mark ensures that the command is executed as a Terminal Command. The output shows that we have created a local Empty git repository.

Git status

We should be able to evaluate the status of the created repository using the Status command

Git status

This would allow us to check the current status of our Repository at any point in time.

Let’s add a New File to the Folder called hello.txt which has a sample text inside it.

Execute the following to see if Git has started tracking changes.

Git Status

The Output should be something similar to this.

This is very informative. Let us evaluate each of the messages before proceeding further.

  1. On branch master: It means that we are currently working on the master branch
  2. No commits yet: We have not made any commits to the repository so far
  3. Untracked files: This shows that git was able to find some files which are part of the folder that git is trying to track
Git Branch

A branch in Git is simply a lightweight movable pointer to one of these commits. The default branch name in Git is master (now main). As you initially make commits, you’re given a master branch that points to the last commit you made. Every time you commit, it moves forward automatically.

Git Commit

Git Commit - Commits are created with the git commit command to capture the state of a project at that point in time. The most recent state of the project is called HEAD.

Effectively we are trying to achieve the following workflow:

We will now add the files that are currently untracked.

Git add .  Git status

We will be adding the un-tracked listed above in our repository. Notice the .; at the end. This is to select all the files. Alternatively, file names can be specified.

The status has not changed to No Commits which specifies that changes are yet to be committed to the branch master.

Before we start committing Git needs to know who we are in order to maintain a name and email ID along with the commits. Execute the following before making a commit. This is a One Time Activity.

git config --global ""
git config --global "Your Name"```

Now, let's Commit

Git commit -m "Initial Commit"

The hyphen m specifies the comment that should be added to commit. Consider it like a changelog that a user can maintain.

The following message confirms that 1 file was changed with 2 lines added into the Git version system. Furthermore, we can track Git Status which we have already learnt.

Working with remote repositories

Github allows you to create remote repositories which can move the project from local to a remote repository.

Git push

After you are done committing your code, it is time to populate your remote repository on Github. This can be done with the Push command on git. If you are working on the master branch and pushing code to the origin repository, then:

git push origin master
Git pull

An easy way to copy an entire repository on a remote repository is to use git clone with the link to the repository on Github. If you would like to download content from a remote repository and match your remote repository to it, you can use git pull.

git pull origin master

You would be accustomed to pulling requests while working in teams. This helps to ensure that contribution by a member is done without affecting the entire workflow and it also acts as a system of the check so that the original repository is not negatively impacted.