Introduction to Git and GitHub

Few key things to know about Git

1. The repository

  • As explained earlier, the repository (commonly known as the ‘repo’) is the directory which contains all the files and the source-code of the project.
  • This repository can be hosted on cloud developer platforms like GitHub and GitLab.
  • Also this repository will be stored locally on your device when using Git on the device or when using your favourite IDE.
  • The repository contains the complete history of the project.

2. Branches

  • Git’s branching is robust, lightweight, and fast.
  • Simply, a Git branch is a movable pointer to a commit.
  • The default branch is main or master. (Of course you need to be much careful when playing with the main branch.)
  • The git checkout command is used to switch between branches
  • Working on different branch apart from the main branch in the development process is a good practice to follow. (Messing up the main branch is always a good hassle to avoid.)
  • These branches can be merged with the main branch. (It’s always a good practice to review and verify the code before merging with the main branch.)
  • These branches can be created and deleted quickly and simply. (Simply you don’t need to be a software engineer to work with branches, it’s that easy.)

4. Commits

  • In Git, commit is a snapshot of the project’s staged changes.
  • A commit includes information about the changes that made to the code, who made those changes, the commit message, and a unique identifier (Known as commit hash).
  • This allows to revert back to previous versions easily, any time.
  • This version history is really helpful in debugging and auditing the code, and in-case when some changes are not right.
  • Also this ensures a smooth and seamless teamwork even in big projects.
  • When we commit, we need to leave a commit message.
  • It is always a good practice to leave a meaningful commit message about the changes that you made, such as a concise summary about the changes made.

5. Push

  • The Git push command is used to upload the commits from the local repository to a remote repository.
  • Git push command synchronizes the local repository with the remote repository.


Pages: 1 2 3 4