Git and GitHub Workshop
Gaurav Rathi
Cloudops Engineer | RHCSA | RHCE | RHCoE(CEPH) ,(OpenShift) | Docker | Ansible | Kubernetes | OpenStack | AWS | MLOps | Jenkins |
What is GIT?
Git is a distributed version control system for tracking changes in any set of files, originally designed for coordinating work among programmers cooperating on source code during software development. Its goals include speed, data integrity, and support for distributed, non-linear workflows (thousands of parallel branches running on different systems). Git was created by Linus Torvalds in 2005 for the development of the Linux kernel, with other kernel developers contributing to its initial development. Since 2005, Junio Hamano has been the core maintainer. As with most other distributed version control systems, and unlike most client-server systems, every Git directory on every computer is a full-fledged repository with a complete history and full version-tracking abilities, independent of network access or a central server.
What is GITHUB?
GitHub, Inc. is a provider of Internet hosting for software development and version control using Git. It offers the distributed version control and source code management (SCM) functionality of Git, plus its own features. It provides access control and several collaboration features such as bug tracking, feature requests, task management, continuous integration and wikis for every project Headquartered in California, it has been a subsidiary of Microsoft since 2018.
GitHub offers its basic services free of charge. Its more advanced professional and enterprise services are commercial.Free GitHub accounts are commonly used to host open-source projects. As of January 2019, GitHub offers unlimited private repositories to all plans, including free accounts, but allowed only up to three collaborators per repository for free.Starting from April 15, 2020, the free plan allows unlimited collaborators, but restricts private repositories to 2,000 minutes of GitHub Actions per month. As of January 2020, GitHub reports having over 40 million users and more than
What is Version Control System?
Version Control System is the software tool that helps the developer team to track and manage all the changes made to the source code over time. Version Control System is provided by SCM (Source Code Management) tool like Git and GitHub. We need versions to do the rollback (to go to the previous code).
Git is a distributed version-control system for tracking changes in any set of files, originally designed for coordinating work among programmers cooperating on source code during software development. Its goals include speed, data integrity, and support for distributed, non-linear workflows.
There are three areas in Git:
- Working Area - The Working Area is the area where you are currently working. This area is untracked.
- Staging Area - The staging Area contains a database that contains the tracking information. This database is known as "Index".
- Commit Area - Commit area contains the snapshot of the data that you added, edited, deleted.
Git Commands:
- git --version - To see the version of Git.
- git init - To initialize a repository.
- git add <file name> - To start tracking.
- git status - To see which changes have been staged and which haven't.
- git commit <file name> - To put file in Commit Area.
- git log - To see history of versions, commit ID, author and time stamp.
- git reflog - To see reference/versions.
- git rest <commit ID> <file name> - To do rollback.
- git branch - To see branches.
- git checkout -b <branch name> - Switch to new branch.
- git checkout master - To switch to master branch.
- git -h - To see help.
- git remote -v - To see centralized system folder.
- git push <repo name> master - To upload history.
- git pull <repo name> master - To download.
- git show <commit ID> - To see what is modified/removed.
- git diff <commit ID 1> <commit ID 2> - To compare between versions.
- git push -u <repo name> <branch name> - To set upstream.
- git merge <branch name> - To merge with master.
- git merge squash -<branch name> - To squash the merge.
- git rebase master - To rebase.
- git rebase --abort - To abort rebase.
We got to know many things like -
- Tools that maintain our source code are known as SCM (Source Code Management) tools.
- Creating a separate branch to develop a feature without disturbing the master branch is known as branching and merging this newly-created branch with the master branch is known as merging.
- Upstream is from where you clone the repository, and downstream is any project that integrates your work with other works.
- A merge happens when combining two branches. Git will take two or more commit pointers and attempt to find a common base commit between them. Git has several different methods to find a base commit, these methods are called merge strategies. There are two types of merge strategies - Fast Forward and Recursive.
- Webhooks are one of a few ways web applications can communicate with each other. It allows you to send real-time data from one application to another whenever a given event occurs. Triggers are a predefined action that activates a webhook or webhooks.
- The squash is an excellent technique for group-specific changes before forwarding them to others. We can merge several commits into a single commit with the compelling interactive rebase command.
- Cherry-picking in Git means to choose a commit from one branch and apply it to another.
- We use Git Stash when we want to record the current state of the working directory and the index, but want to go back to a clean working directory.
- There are three types of reset - mixed, soft, and hard resets. Mixed reset remove versions from staging and commit area. Soft reset removes the version from the commit area but keeps it in the staging area. Hard reset removes the versions from the staging, commit and work in progress area.
Tools which we have used in the workshop -
- GitBash - It is an application that allows us to run Git from the command line.
- GitHub - It is a code hosting platform for version control and collaboration. It lets you and others work together on projects from anywhere in the world.
- GitKraken - It is a software product for developers and dev teams to help them maximize their productivity with a beautiful and intuitive GUI.
- P4Merge - It is a visual diff tool that displays the differences between file versions and helps you to resolve conflicts and merge competing versions into one.
What is Branching?
Branching: Branches help you to work on different versions of a repository at one time. Let’s say you want to add a new feature (which is in the development phase), and you are afraid at the same time whether to make changes to your main project or not. This is where git branching comes to the rescue. Branches allow you to move back and forth between the different states/versions of a project. In the above scenario, you can create a new branch and test the new feature without affecting the main branch. Once you are done with it, you can merge the changes from the new branch to the main branch. Here the main branch is the master branch, which is there in your repository by default. Refer to the below image for better understanding:
Branching
The newly initialized repository created results in a default master branch. Synonymous with production, typically commits are not made directly to this, but rather are reviewed and merged in.Branches can be thought of as an area to silo were to commit. Its reference is specifically a moving pointer to an individual commit object.
What is P4merge?
P4Merge
Using P4Merge to track and compare the effects of past and pending work for branches and individual files with P4Merge. You can also use it to resolve conflicts (even with Git).
Key Features of P4Merge
Visualize Your Merges
Visualize the differences between file versions with P4Merge. Resolve conflicts that result from parallel or concurrent development via color coding and:
- Highlight and edit text file differences.
- Choose to include or ignore line endings or white spaces.
- Recognize line-ending conventions for Windows (CRLF), Mac (CR), and Unix (LF).
- Use command-line parameters and launch from non-Perforce applications.
- Display line numbers when comparing and merging files
Thank You Vimal Daga Sir