Git Version Control

Git is, at its core, a version control system designed to assist developers in monitoring changes made to their codebase over time. It maintains a record of file modifications and enables efficient collaboration amongst different users on projects.

Basic Git Terminalogies:

  • Repository: It is an group of files and directories that have been modified over time. It's frequently shortened to "repo." Usually, every project has its own repository.

  • Branch: A branch is a subset of the codebase that is separate from the "master" branch, which is the main line of development. Using branches, developers can individually work on features or fixes without affecting the source code.

  • Commit: A commit is a snapshot of the changes made to the repository's files at a particular instance of time.

  • Merge: Combining the modifications from one branch into another is known as a merge. It is mostly used to add updates or new features into the primary source code.

  • Pull Request: A PR is a request to merge changes from one branch into another. It is usually used in an collaborative development environment where team members evaluate and discuss suggested changes prior to merging them.

  • Clone: The process of making a clone of a repository locally on your computer is called cloning. This allows developers to work on a code base locally and the push the changes via pull requests.

  • Remote: It is basically a version of a repository that is hosted on a server like GitHub, GitLab, Bitbucket, etc.

Git Commands

  • git version: This command is used to find out the current version of git that is being used on the system.

      git --version
    
  • git init: Used to initialize a new git repository in the current working directory.

      git init
    
  • git status: This command is used to show the current state of a file i.e. whether the file is staged, unstaged or untracked.

      git status
    
  • git add: It is used to add from working area to staging area.

      git add .
    
  • git branch: Used to list your branches and will appear next to the currently active branch.

      git branch <branch_name>
    
  • git checkout: Used to switch to another branch and it is also used to checkout into your working directory.

      git checkout <branch_name>
    
  • git push: This command is used to push committed changes from the local branch to the remote repository.

      git push <remote_name> <branch_name>
    
  • git pull: This command is used to fetch and merge any commits from the collaborative remote repository.

      git pull <remote_name> <branch_name>
    
  • git log: It is used to display all the commit logs whether on the local machine or remotely.

      git log