Git and GitHub Documentation
Introduction
In this Documentation, you will learn about Git, GitHub and to work with them.

Learn about VCS or version control system, Git and its commands, how to work with GitHub and why this is so important for you as a developer.

What is Git?

Git is a distributed version control system. A version Control system is a system that maintains different versions of your project when we work in a team or as an individual. (system managing changes to files) As the project progresses, new features get added to it.

So, a version control system maintains all the different versions of your project for you and you can roll back to any version you want without causing any trouble to you for maintaining different versions by giving names to it like MyProject, MyProjectWithFeature1, etc.

Distributed Version control system means every collaborator(any developer working on a team project)has a local repository of the project in his/her local machine unlike central where team members should have an internet connection to every time update their work to the main central repository.

Git Repository Structure

It consists of four parts:

  • The Working directory: The local directory where you make the actual project and make changes to it.
  • The staging area (index): Where you first need to put your project before committing. This is used for code review by other team members.
  • The Local Repository: Where where you commit changes to the project before pushing them to the central repository on Github. This is what is provided by the distributed version control system. This corresponds to the .git folder in our directory.
  • The Central Repository: This is the main project on the central server, a copy of which is with every team member as a local repository.
Github

Github basically is a for-profit company owned by Microsoft, which hosts Git repositories online. It helps users share their git repository online, with other users, or access it remotely. You can also host a public repository for free on Github.

User share their repository online for various reasons including but not limited to project deployment, project sharing, open source contribution, helping out the community and many such.

Accessing Github

Here, transfer project means transfer changes as git is very lightweight and works on changes in a project.

It internally does the transfer by using Lossless Compression Techniques and transferring compressed files. Https is the default way to access Github central repository.

  • By git remote add origin http_url: remote means the remote central repository. Origin corresponds to your central repository which you need to define (hereby giving HTTPS URL) in order to push changes to Github.
  • Via SSH: connect to Linux or other servers remotely.
Working With Git

Here are the important Git commands:

  1. Git user configuration:
  2. git --version git config --global user.name "your username" git config --global user.email "your email"

    These are the information attached to commits.

  3. Directory Initialization:
  4. git init

    initializes your directory to work with git and makes a local repository. .git folder is made

    git clone http_url

    This is done if we have an existing git repository and we want to copy its content to a new place.

  5. Connecting to the remote repository:
  6. connect to the central repo to push/pull. pull means adopting the changes on the remote repository to your local repository. push merges the changes from your local repository to the remote repository.

    git remote add origin http_url/ssh_url

    One should always first pull contents from the central repo before pushing so that you are updated with other team members’ work. It helps prevent merge conflicts. Here, master means the master branch (in Git).

    git pull origin master
Reference

this is part of the freeCodeCamp project, all information was retrived from GfG