Introduction to GIT & GIThub Presented By : Ritesh Kumar
Topics to be discussed Git & Github Introduction GIT & Github Difference A little on VCS GIT Terminology & GIT commands and live demo GIT flow GIT installation & Account on GIT? GIT behind the scenes Branches in GIT Diff Stash & Tags Rebase & Reflog 1 2 3 4 6 7 8 10 9 Getting started with Github 11 5
GIT & Github Introduction → Git is a version control system that allows you to track changes to your files and collaborate with others. → It is used to manage the history of your code and to merge changes from different branches. What does Git do? ● Manage projects with Repositories ● Clone a project to work on a local copy ● Control and track changes with Staging and Committing ● Branch and Merge to allow for work on different parts and versions of a project ● Pull the latest version of the project to a local copy ● Push local updates to the main project
GIT & Github Difference GIT Git is a version control system that is used to track changes to your files. It is a free and open- source software that is available for Windows, macOS, and Linux. Remember, GIT is a software and can be installed on your computer. Github Github is a web-based hosting service for Git repositories. Github is an online platform that allows you to store and share your code with others. It is a popular platform for developers to collaborate on projects and to share code. It is not that Github is the only provider of Git repositories, but it is one of the most popular ones. There are many more like bitbucket,gitlab etc.
A Little on VCS VCS ( Version Control System) Version control systems are used to manage the history of your code. Version control systems are essential for software development Consider version control as a checkpoint in game. You can move to any time in the game and you can always go back to the previous checkpoint. This is the same concept in software development. Before Git became mainstream, version control systems were used by developers to manage their code. They were called SCCS (Source Code Control System). SCCS was a proprietary software that was used to manage the history of code. It was expensive and not very user- friendly. Git was created to replace SCCS and to make version control more accessible and user- friendly.
Git & Github Installation Go to git-scm.com/downloads and download as per your system. Download and install the latest version of GitHub Desktop. This will automatically install Git and keep it upto-date for you. Link : https://desktop.github.com/
GIT Terminology Check your git version To check your git version, you can run the following command: Terminal window This command will display the version of git installed on your system. Git is a very stable software and don’t get any breaking changes in majority of the cases, at least in my experience.
GIT Terminology Contd. Your config settings Github has a lot of settings that you can change. You can change your username, email, and other settings. Whenever you checkpoint your changes, git will add some information about your such as your username and email to the commit. There is a git config file that stores all the settings that you have changed. Let’s setup your email and username in this config file. I would recommend you to create an account on github and then use the email and username that you have created. Now you can check your config settings: Git config --list This will show you all the settings that you have changed.
GIT Terminology Contd. Repository A repository is a collection of files and directories that are stored together. It is a way to store and manage your code. A repository is like a folder on your computer, but it is more than just a folder. It can contain other files, folders, and even other repositories. You can think of a repository as a container that holds all your code. There is a difference between a software on your system vs tracking a particular folder on your system. At any point you can run the following command to see the current state of your repository:
GIT Terminology Creating a repository Creating a repository is a process of creating a new folder on your system and initializing it as a git repository. It’s just regular folder to code your project, you are just asking git to track it. To create a repository, you can use the following command : git status command will show you the current state of your repository. git init command will create a new folder on your system and initialize it as a git repository. This adds a hidden .git folder to your project.
GIT Terminology Contd.
Complete GIT Flow When you want to track a new folder, you first use init command to create a new repository. Then you can use add command to add the folder to the repository. After that you can use commit command to save the changes. Finally you can use push command to push the changes to github. Of course there is more to it but this is the basic flow.
GIT Terminology Contd.
GIT Terminology Contd.
GIT Terminology Contd.
GIT Terminology Contd.
GIT behind the Scenes Git Snapshots A git snapshot is a point in time in the history of your code. It represents a specific version of your code, including all the files and folders that were present at that time. Each snapshot is identified by a unique hash code, which is a string of characters that represents the contents of the snapshot. A snapshot is not an image, it’s just a representation of the code at a specific point in time. Snapshot is a loose term that is used when git stores information about the code in a locally stored key-value based database. Everything is stored as an object and each object is identified by a unique hash code.
GIT behind the Scenes Contd. GIT stores data internally using below 3 Objects : ● Commit Objects ● Tree Objects ● Blob Objects
GIT behind the Scenes Contd. Commit Object Each commit in the project is stored in .git folder in the form of a commit object. A commit object contains the following information: ● Tree Object ● Parent Commit Object ● Author ● Committer ● Commit Message Tree Object Tree Object is a container for all the files and folders in the project. It contains the following information: ● File Mode ● File Name ● File Hash ● Parent Tree Object Everything is stored as key-value pairs in the tree object. The key is the file name and the value is the file hash. Blob Object Blob Object is present in the tree object and contains the actual file content. This is the place where the file content is stored.
GIT behind the Scenes Contd. Helpful Commands to view Commits,tree,Blob Here are some helpful commands that you can use to explore the git internals: git show -s --pretty=raw <commit-hash> [This will show all the information of the particular commit Id] Commit IDs can be obtained using below commands : → git log –oneline [ Grab tree id from the above command and use it in the following command to get the tree object:] git ls-tree <tree-id> [Grab tree id from the above command and use it in the following command to get the blob object:] git show <blob-id> [Grab tree id from the above command and use it in the following command to get the commit object:] git cat-file -p <commit-id>

GIT & Github introduction for beginners

  • 1.
    Introduction to GIT &GIThub Presented By : Ritesh Kumar
  • 2.
    Topics to bediscussed Git & Github Introduction GIT & Github Difference A little on VCS GIT Terminology & GIT commands and live demo GIT flow GIT installation & Account on GIT? GIT behind the scenes Branches in GIT Diff Stash & Tags Rebase & Reflog 1 2 3 4 6 7 8 10 9 Getting started with Github 11 5
  • 3.
    GIT & Github Introduction →Git is a version control system that allows you to track changes to your files and collaborate with others. → It is used to manage the history of your code and to merge changes from different branches. What does Git do? ● Manage projects with Repositories ● Clone a project to work on a local copy ● Control and track changes with Staging and Committing ● Branch and Merge to allow for work on different parts and versions of a project ● Pull the latest version of the project to a local copy ● Push local updates to the main project
  • 4.
    GIT & Github Difference GIT Gitis a version control system that is used to track changes to your files. It is a free and open- source software that is available for Windows, macOS, and Linux. Remember, GIT is a software and can be installed on your computer. Github Github is a web-based hosting service for Git repositories. Github is an online platform that allows you to store and share your code with others. It is a popular platform for developers to collaborate on projects and to share code. It is not that Github is the only provider of Git repositories, but it is one of the most popular ones. There are many more like bitbucket,gitlab etc.
  • 5.
    A Little onVCS VCS ( Version Control System) Version control systems are used to manage the history of your code. Version control systems are essential for software development Consider version control as a checkpoint in game. You can move to any time in the game and you can always go back to the previous checkpoint. This is the same concept in software development. Before Git became mainstream, version control systems were used by developers to manage their code. They were called SCCS (Source Code Control System). SCCS was a proprietary software that was used to manage the history of code. It was expensive and not very user- friendly. Git was created to replace SCCS and to make version control more accessible and user- friendly.
  • 6.
    Git & Github Installation Goto git-scm.com/downloads and download as per your system. Download and install the latest version of GitHub Desktop. This will automatically install Git and keep it upto-date for you. Link : https://desktop.github.com/
  • 7.
    GIT Terminology Check yourgit version To check your git version, you can run the following command: Terminal window This command will display the version of git installed on your system. Git is a very stable software and don’t get any breaking changes in majority of the cases, at least in my experience.
  • 8.
    GIT Terminology Contd. Yourconfig settings Github has a lot of settings that you can change. You can change your username, email, and other settings. Whenever you checkpoint your changes, git will add some information about your such as your username and email to the commit. There is a git config file that stores all the settings that you have changed. Let’s setup your email and username in this config file. I would recommend you to create an account on github and then use the email and username that you have created. Now you can check your config settings: Git config --list This will show you all the settings that you have changed.
  • 9.
    GIT Terminology Contd. Repository A repositoryis a collection of files and directories that are stored together. It is a way to store and manage your code. A repository is like a folder on your computer, but it is more than just a folder. It can contain other files, folders, and even other repositories. You can think of a repository as a container that holds all your code. There is a difference between a software on your system vs tracking a particular folder on your system. At any point you can run the following command to see the current state of your repository:
  • 10.
    GIT Terminology Creating arepository Creating a repository is a process of creating a new folder on your system and initializing it as a git repository. It’s just regular folder to code your project, you are just asking git to track it. To create a repository, you can use the following command : git status command will show you the current state of your repository. git init command will create a new folder on your system and initialize it as a git repository. This adds a hidden .git folder to your project.
  • 11.
  • 12.
    Complete GIT Flow Whenyou want to track a new folder, you first use init command to create a new repository. Then you can use add command to add the folder to the repository. After that you can use commit command to save the changes. Finally you can use push command to push the changes to github. Of course there is more to it but this is the basic flow.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
    GIT behind the Scenes GitSnapshots A git snapshot is a point in time in the history of your code. It represents a specific version of your code, including all the files and folders that were present at that time. Each snapshot is identified by a unique hash code, which is a string of characters that represents the contents of the snapshot. A snapshot is not an image, it’s just a representation of the code at a specific point in time. Snapshot is a loose term that is used when git stores information about the code in a locally stored key-value based database. Everything is stored as an object and each object is identified by a unique hash code.
  • 18.
    GIT behind the ScenesContd. GIT stores data internally using below 3 Objects : ● Commit Objects ● Tree Objects ● Blob Objects
  • 19.
    GIT behind the ScenesContd. Commit Object Each commit in the project is stored in .git folder in the form of a commit object. A commit object contains the following information: ● Tree Object ● Parent Commit Object ● Author ● Committer ● Commit Message Tree Object Tree Object is a container for all the files and folders in the project. It contains the following information: ● File Mode ● File Name ● File Hash ● Parent Tree Object Everything is stored as key-value pairs in the tree object. The key is the file name and the value is the file hash. Blob Object Blob Object is present in the tree object and contains the actual file content. This is the place where the file content is stored.
  • 20.
    GIT behind the ScenesContd. Helpful Commands to view Commits,tree,Blob Here are some helpful commands that you can use to explore the git internals: git show -s --pretty=raw <commit-hash> [This will show all the information of the particular commit Id] Commit IDs can be obtained using below commands : → git log –oneline [ Grab tree id from the above command and use it in the following command to get the tree object:] git ls-tree <tree-id> [Grab tree id from the above command and use it in the following command to get the blob object:] git show <blob-id> [Grab tree id from the above command and use it in the following command to get the commit object:] git cat-file -p <commit-id>