You are on page 1of 13

Git Fundamentals

By
Mohammad Wahid Hassan
Backend Engineer
Shikhao
Outline of Day 1
1. What is Git?
2. What is version controlling?
3. Why use Git?
4. Installation
5. Operating Principle of Git
6. Git Repository
7. Staging Files
8. Making Commits
9. Reversing Things (Checkout commit, Revert commit, Reset commit)
10. Branches
What is Git?
● Git is a free and open source distributed version control system designed to
handle everything from small to very large projects with speed and efficiency.
● Created by Linus Torvalds in 2005 for development of the Linux kernel.
What is version controlling?

We have all been essentially doing


our interpretation of version
controlling without even knowing!
Why use Git?
● It systematically records versions of our code in history. Hence, version
controlling.
● It can easily restore a specific version of our code.
● It supports collaboration on project between many programmers.
● Supports the storage of the total codebase on a remote host such as Github,
Gitlab, and many more.
Installations
For this course we will only need Git Bash which comes packaged with Git.
And some type of test editor. Sublime, Atom, Notepad etc.

Please visit the link below and download it.

Install it. I’ll wait…………………..

https://git-scm.com/downloads
Operating Principle of Git (Repositories)
At the foundation of Git, there are Repositories.

Then there are Branches.


Operating Principle of Git (Git Sequence)

Modified Staging Committed

Changed files but not Add any changed files to Any files in the staging area
committed staging that you want to are added to the commit
commit when we make one
Git Repository
● Repositories are essentially folders containing your project.
● Any subfolders and files inside the root folder are also included in the repo.
● Repo can be created inside an empty folder or a folder containing an existing
project.

Let’s create a repository:

In your project directory path, open Git Bash.

In Git Bash terminal type: git init


Staging Files
● In your project folder create a file named “index.html”
○ Type in Git Bash: touch index.html
○ Open it with text editor

● Now enter the command: git status


● To transfer the file into the staging area use the command: git add “filename”
● We can also use “git add . ” to enter all the contents of the directory.
Making Commits
● It is better to use the command “git status” before committing your changes.
● To commit type, “git commit -m ‘Your Message’ ”
● To view your commit history use the command “git log”
○ View them in one line using the command “git log --oneline”
Reversing Things
● Type “git checkout ‘commit_id’ ”
Checkout Commit ● To go back type “git checkout master”

● Type “git revert ‘commit_id’ ”


Revert Commit
● To go back type “git revert ‘revert commit_id’ ”

● Type “git reset ‘commit_id’ ”


Reverse Commit
● For complete deletion “git reset ‘commit_id’ --hard”
Branches
● One Repository can have many branches.
● Branches are the mechanism for multiple programmers to collaborate.
● Usually a branch is created to in order to implement a feature the project
● Some git commands:
○ git branch “your-branch-name” //Creates new branch
○ git branch -a //Shows all the branches
○ git checkout “your-branch-name” //Goes to that branch

You might also like