Understanding GIT

Understanding GIT

ยท

4 min read

Table of contents

No heading

No headings in the article.

Git is a ๐๐ข๐ฌ๐ญ๐ซ๐ข๐›๐ฎ๐ญ๐ž๐ ๐ฏ๐ž๐ซ๐ฌ๐ข๐จ๐ง ๐œ๐จ๐ง๐ญ๐ซ๐จ๐ฅ ๐ฌ๐ฒ๐ฌ๐ญ๐ž๐ฆ which is free and open source. It records changes to your files over time, so you can revert back to any specific version when you want to. Nowadays most of the developers are using a source (version) control system not only to track changes of their code during software development but also for collaborating with other developers.

Git allows multiple local branches that can be entirely independent of each other. This means you can:

  • have a branch that always contains only what goes to production, another that you merge work into for testing, etc.
  • create new branches for each new feature you're working on so you can seamlessly switch back and forth between them
  • create a branch to experiment in, realize it's not going to work and just delete it, with nobody else ever seeing it.

Unlike other systems, Git has staging area, an intermediate area, where commits can be formatted and reviewed before completing the commit.

I would recommend Git to everyone doing any kind of software development. Specially for new developers, hosting their code on Github, GitLab, BitBucket, etc. can really benefit them by getting their checked-in code reviewed by others. ๐˜›๐˜ฉ๐˜ช๐˜ด ๐˜ช๐˜ด ๐˜ฐ๐˜ฏ๐˜ฆ ๐˜ฐ๐˜ง ๐˜ต๐˜ฉ๐˜ฆ ๐˜ฃ๐˜ฆ๐˜ด๐˜ต ๐˜ธ๐˜ข๐˜บ ๐˜ต๐˜ฐ ๐˜ช๐˜ฎ๐˜ฑ๐˜ณ๐˜ฐ๐˜ท๐˜ฆ ๐˜บ๐˜ฐ๐˜ถ๐˜ณ ๐˜ค๐˜ฐ๐˜ฅ๐˜ช๐˜ฏ๐˜จ ๐˜ด๐˜ฌ๐˜ช๐˜ญ๐˜ญ๐˜ด.โฃโฃ

Though Git is quite easy to use, it can be a little overwhelming when you are starting with it. In this post, I have explained few of the most common terms you will be dealing with in your day to day coding life. Understanding these terms is really necessary as while working on projects with others, you will often hear something like "checkout a branch from origin/master", "fork this repo", "raise a pull request", etc. Let's look at them one by one:

  1. Repo - You can think Git Repo (or Git Repository) as a directory that stores all the files, folders and content needed for your project. It actually is the object database of the project, storing everything from the files themselves to the versions of the files, commits, deletions, etc.
  2. Local Repository - Another term for where you keep the copy of Git repository on your local workstation.
  3. Remote Repository - Another copy of your Git Repository where you push your changes for backup or collaboration.
  4. Clone a repo - Cloning downloads an existing git repo to your local workstation. As a convenience, cloning automatically creates a remote connection called "origin" pointing back to the original repository.
  5. Fork a repo - A fork is a separate copy of a repository. Forking a repo allows you to freely experiment with changes without affecting the original project.
  6. Commit - Commit is used to save your changes to local repository.
  7. Branch - Branch is a pointer to a commit.
  8. Checkout - It is used to switch between branches.
  9. origin - origin is the default name of a remote repository connection.
  10. main - main is the default branch name in Git when we first initiate Git. NOTE: Earlier the default branch name used to be master. So, if you are going to work on old git repo, there are high chances that you'll encounter the default branch name as master.
  11. origin/main - origin/main is a remote branch, which has a local branch named main on a remote named origin.
  12. HEAD - HEAD is a reference to the last commit in the current branch.
  13. Index or Staging Area - It is the cache/place where the changes are stored before they are committed.
  14. Stash - Another cache where changes can be stored without committing.
  15. push - push is used to store local repo changes (commits) to a remote repo.
  16. pull - pull downloads new data from remote repo and integrates it into current working copy files.
  17. fetch - fetch downloads new data from remote repo but doesn't integrate any new data into current working copy files.
  18. merge - Merging takes the content of a source branch and integrates them with a target branch.
  19. Merge conflicts - Merge conflicts happen when you merge branches that have competing commits and Git is unable to resolve differences between them.
  20. Pull Request - It lets you tell others about changes you've pushed to a branch in a repo on Github.

At first these terms might look a lot but these are most commonly used git terms you must be familiar with. You don't need to memorize them at once. Bookmark this post and come back when you need to understand something.

Did you find this article valuable?

Support Shubhaw's Blog by becoming a sponsor. Any amount is appreciated!

ย