← Back to Blog

GIT

GIT

Introduction to Git

Git is one of the free and open-source distributed version control systems. Git is responsible for everything happens on GitHub related locally on the computer.

Benefits of Git

Git helps us manage our project files. It permits working together on the same project at the same time without disturbing each other's files. Collaboration is easy with Git. All team members can work on different features and easily merge all changes.

Git illustration

Some basic terminology used in Git

1. Repository

A repository might be a storage space where you can go live for your projects. Most of the time GitHub users abbreviate this to “repo”. It is a local folder on your computer or storage space on GitHub. You can store code records, content records, and picture records inside a repository.

To create a new repository, go to the new repository option and provide a short and memorable name. You can change the settings, private or public access.

Repository illustration

There are three forms in which a repository can be started:

1. Open - Open a repository as already opened or initialized, and which is usually available locally

2. Clone - Clone a remote Git repository as of now initialized.

3. Init - Create an empty repository and open a local project repository.

2. Open

To load and pick up your existing folder where you left. It is also useful to see past work which is completed. To start opening File->Open Repo.

Open repository

3. Clone

A clone is basically a copy of a repository that lives on your computer rather than on a server. To start opening File->Clone Repo.

Clone repository

Using Command:

git clone [URL of the repo]

4. Init

Init helps initialize a new project and local project. Moreover, starting a project is easy through File->Init.

Init repository

Using Command:

git init [repository name]

5. Branch

For one project, you can create multiple branches. The branch is used by more than one developer. They can work at the same time, but that work does not go live on the main remote repository. They can commit to a specific branch in the repo. After merging off of the main branch with their own changes, the master of the project is the main remote directory.

When you are creating a new branch, your changes live on that branch and do not affect the master branch. Anything in the master branch is always deployable.

Branch illustration

Using Command:

git branch [branch name]

For switching from one branch to another branch:

git checkout [branch name]

For merging the specific branch history into the current branch:

git merge [branch name]

6. Commit

It is the power command of Git. Commit is also used as Push. It takes local changes and makes them live on the remote. Changes pushed on currently checked out branch by clicking the top toolbar.

Commit and Push

Using Command:

git commit -m "[commit message]"

7. Pull

Remote pulling updates and bringing them into your local folder.

Pull updates

There are 4 pulling types:

1. Fetch All: Getting updates from remote sites, but not bringing any of these new data into your working file.

Using Command: git fetch --all

2. Pull (fast-forward if possible): Pull will get any updates on the remote branch and then try to move the local branch forward quickly.

Using Command: git pull [Repository link]

3. Pull (fast-forward only): Pull gets all updates and then tries to move fast-forward.

Using Command: git fetch --ff-only

4. Pull (rebase): Pull stashes all commits on this branch, pulls through new commits from the remote and then replays the commits.

Using Command: git fetch --rebase

8. Pull Requests

Pull Requests initiate a discussion about your commits. Since they tightly coordinate with the basic Git store, anybody can see precisely what changes would be combined in case they accept your task. Pull Requests are valuable for contributing to open source projects and for overseeing changes to be shared on repositories. Pull Requests are basically a code review process.

Pull Requests

9. Undo and Redo

To remove the last commit from git use Undo. For reverting undo changes, use Redo.

Undo Redo

Using Command:

git reset HEAD^

git reset HEAD~2 (for removing multiple commits)

10. Stash

Stash is used for storing safely in a specified place. Reserved changes show up within the cleared out Stash board, where any stash can be applied, popped, or deleted.

Stash

Using Command:

git stash save

11. Pop

Pop is the vice versa of stash. It is used to restore the most recently stashed files.

Using Command:

git stash pop

12. Git Folder

When initializing a Git repo or cloning from a remote, you may notice a .git folder in the project root. This contains all of the data required for the Git repository and if this folder is deleted, you would not be able to switch branches, pull from remotes, or view commit history.