Git is a version-control system for tracking changes in source code during software development. It is designed for coordinating work among programmers.
Github brings together the world’s largest community of developers to discover, share, and build better software.
We will use Github as the platform to practice our learning.
Let’s Begin by Creating a Local Repository (Execute the command in a Cell)
> Git init
Initialized 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.
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.
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
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.
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
hello.txt
nothing added to commit but untracked files present (use "git add" to track)
This is very informational. Let us evaluate each of the messages before proceeding further.
Message Description On branch master We are currently working on master branch .No commits yet have not made any commits to the repository so far. Untracked files found some files which are listed below this message. This implies that Git was able to find some files which are part of the folder which Git is Tracking for changes.
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. 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 - Commits are created with the git commit command to capture the state of a project at that point in time.
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 “dot” at the end. This is to select all the files. Alternatively, file names can be specified.
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: hello.txt
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 user.email "you@example.com"
> git config --global user.name "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 change log that a user can maintain.
[master (root-commit) 4bf0552] Initial Commit
1 file changed, 2 insertions(+)
create mode 100644 hello.txt
The following message confirms that 1 files was changed with 2 lines added into Git version system. Furthermore we can track Git Status which we have already learnt.
To learn about the next 2 important steps
1. Branching
2. Merging
Follow us here on substack and for more such content check out our YouTube channel.