Git Introduction

Chaithanya Kopparthi
3 min readJun 13, 2021

--

Git is a version control system, that allows multiple developers contribute to the source code.

Git tracks and maintains the changes that developers do to the repository thus prevents developers to overwrite the changes. Enabling multiple developers to work on the same repository.

Git Installation:

If you are using mac install git using homebrew

$ brew install git

Git Workflow:

  • Clone your repository from GitHub, this will be the working copy.
  • Make changes to the working copy and add the changes to the staging area.
  • Once all the changes are made commit the changes, this will add your files to the local repository.
  • Push your changes from the local repository to the remote repository.

Clone Git Repository:

Cloning git repository will create a copy of the current version of source code that is present in the git server.

$ git clone https://github.com/chaitukopparthi/test.git

Staging Area:

Staging area keeps track for all the file that is being changed and also keeps a list of files that need to be added to the next commit.

Git status command will list all the files that are not staged and not tracked by git.

$ git status
On branch main
Your branch is up to date with 'origin/main'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: example.py
Untracked files:
(use "git add <file>..." to include in what will be committed)
README

To add the files to the staging area, use the below command.

$ git add README example.py

Commit changes to Git repository:

Commit record’s the changes in the staging area and will add a hash to it. Git will not make any changes to the commit unless one force to make changes.

$ git commit -m "My Initial Commit"
[main a280745] My Initial Commit
2 files changed, 2 insertions(+), 1 deletion(-)
create mode 100644 README

After the commit is made, one can check all the commits using the git log command. That will display all the details regarding the commit. Such as Commit hash, Author, Files to which the changes are made, Short description for the changes made.

$ git log -1
commit a280745b25219b70290fac92cb1dd46b79451946 (HEAD -> main)
Author: Chaithanya Kopparthi <chaitukopparthi@gmail.com>
Date: Sun Jun 13 23:42:39 2021 +0530
My Initial Commit

Push changes to the remote repository:

Git push will push all the changes made to the local repository to the remote repository in the central GitHub server. So all the collaborators to that repo can view your changes.

$ git push origin main
Enumerating objects: 20, done.
Counting objects: 100% (20/20), done.
Delta compression using up to 16 threads
Compressing objects: 100% (11/11), done.
Writing objects: 100% (11/11), 1.66 KiB | 1.66 MiB/s, done.
Total 11 (delta 8), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (8/8), completed with 8 local objects.
To github.com:chaitukopparthi/test.git

To pull all the changes made by other collaborators git pull command can be used.

$  git pull
Already up to date.

--

--