Table of contents
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:
- 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.
- Local Repository - Another term for where you keep the copy of Git repository on your local workstation.
- Remote Repository - Another copy of your Git Repository where you push your changes for backup or collaboration.
- 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.
- 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.
- Commit - Commit is used to save your changes to local repository.
- Branch - Branch is a pointer to a commit.
- Checkout - It is used to switch between branches.
- origin -
origin
is the default name of a remote repository connection. - main -
main
is the default branch name in Git when we first initiate Git. NOTE: Earlier the default branch name used to bemaster
. So, if you are going to work on old git repo, there are high chances that you'll encounter the default branch name asmaster
. - origin/main -
origin/main
is a remote branch, which has a local branch namedmain
on a remote namedorigin
. - HEAD -
HEAD
is a reference to the last commit in the current branch. - Index or Staging Area - It is the cache/place where the changes are stored before they are committed.
- Stash - Another cache where changes can be stored without committing.
- push -
push
is used to store local repo changes (commits) to a remote repo. - pull -
pull
downloads new data from remote repo and integrates it into current working copy files. - fetch -
fetch
downloads new data from remote repo but doesn't integrate any new data into current working copy files. - merge - Merging takes the content of a source branch and integrates them with a target branch.
- Merge conflicts - Merge conflicts happen when you merge branches that have competing commits and Git is unable to resolve differences between them.
- 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.