8 Hours Journey of Git and GitHub with Vimal Daga Sir
So, let me start from a small scenerio to explain what I learnt
Consider developer is developing the WebApp. Workspace is the working area where developer develops the code. Now, we need to keep backup of this code. We choose option to deploy the code. Now imagine what if the code fails and whole website got crash!
Deploying the code in Production System is not an good idea. We store our all backup in the Commit Area. But instead of storing all the data directly to the Commit Area we keep the SCM tool as intermediate.
What is SCM tool?
The Source Code Management (SCM) tool helps us to manage our real time database. It works in a Staging Area. It does not stores whole data it stores the part of data that is been modified. All tracking information (history) of data is stored here. Once we feel our code is working great we can shift it to the Commit Area.
What is GIT?
Linus Torvalds developed an open source SCM tool designed to handle everything from small to very large projects with speed and efficiency. Version Control System is the facility of SCM tool.
Git helps to store our code in the Commit Area. In addition it will keep track of line that is been - edited, added or deleted in index file.
What is Github?
GitHub is a web-based version-control and collaboration platform for software developers.
GitHub facilitates social coding by providing a web interface to the Git code repository and management tools for collaboration.
Features of Git and Github:
- Helps developers and programmers to collaboratively work on code.
- It provides each developer a local copy of the entire development history, and changes are copied from one such repository to another.
IS GIT AND GITHUB SAME ?
- Git is installed locally on a system, so developers can manage their source code history using their local machines as repositories.
- This means there is no centralized server required to use Git, and no needed internet access either. Additionally, there is no user-management system available.
- GitHub, meanwhile, lives in the cloud, so Internet access is required. It is a web-based hosting service for Git repositories.
- It also has a built-in user-management system. GitHub features a desktop version that can be installed on local computers to help synchronize code.
The Installation and Git Configuration:
1) Click here to download Git ---> Download Git
2) Click the download link for Windows and allow the download to complete further install it.
Let us know about few command in Git
Now, you need to know that workspace is nothing but the folder in which we all perform an activity. So to create a workspace:
1) mkdir workspace
2) To create a new Git repository - git init
3) Create file main.py
4) To start tracking the file - git add main.py
5) The commit command is used to save your changes to the local repository as
git commit main.py
6) git status - displays the state of the working directory and the staging area. It lets you see which changes have been staged, which haven't, and which files aren't being tracked by Git.
7) To add comment in command line while commiting-
git commit -m "<comment>" <file_name>
8) to go back to previous version
- find id of commit using git log or git reflog or git log --oneline
- git reset <commit_id_to_go_back>
9) Git push - The git push command is used to transfer or push the commit, which is made on a local branch in your computer to a remote repository like GitHub.
git push <repo_name> <branch_name>
10) Git pull - If you make a change in a repository, GIT PULL can allow others to view the changes.
git pull <repo_name> <branch_name>
11) Use git add in your bash to add the files to the given folder.
git add <filename>
12) git fetch - Helps to download the history
Branching and Merging
- Branching -
Consider that Production System is connected to the main storage [master]. We create extra storage for development and make changes there.
Once the edit is done or app is working great we add it to production system. So, we test code in development part and update it to the main area. It is branching.
A branch in Git is simply a lightweight movable pointer to one of these commits. The default branch name in Git is main (i.e.master)
- git branch
- To move to other branch- git checkout master or git checkout dev
2. Merging -
Merging uses the strategy of Fast-Forwarding. The multiple branches are merged (joined) here.
Here we append the history of one branch to another.
- git merge master or git merge dev
Upstream and Downstream
Generally, upstream is from where you clone the repository, and downstream is any project that integrates your work with other works.
The downstream repo will be pulled from the upstream repository. Data will flow downstream naturally.
git push --set-upstream origin master
Git Fork
A fork is a rough copy of a repository. Forking a repository allows you to freely test and debug with changes without affecting the original project. One of the excessive use of forking is to propose changes for bug fixing. To resolve an issue for a bug that you found, you can:
- Fork the repository.
- Make the fix.
- Forward a pull request to the project owner.
Forking is not a Git function; it is a feature of Git service like GitHub.
Git Rebase
Rebase is a process to reapply commits on top of another base trip. It is an alternative of git merge command. It is a linear process of merging.
In Git, the term rebase is referred to as the process of moving or combining a sequence of commits to a new base commit.
Git Squash
In Git, the term squash is used to squash the previous commits into one.
The squash allows us to rewrite history. Suppose we have made many commits during the project work, squashing all the commits into a large commit is the right choice than pushing.
GitKraken
It is a GUI tool used to provide gut API and used to manage all the things in local repository.
Webhooks
We can use this hooks to automate the next step.
Suppose we what we want is whenever we run the push command it should be automatically appended. Capability to get something automatically done is trigger.
When you get something triggered the program behind the scene we use is hooks.
This is my short reflection on what we learnt. Thank you Sir for sharing such a great knowledge!
Terraform || Openshift(EX180) || AWS(CLF-CO2) || AWS(SAA-C03) Certified
4 年Excellent work???? Hasti Vora, workshop was really amazing
DevOps Engineer || Python || Docker || Ansible || Kubernetes || AWS || Jenkins || Buildkite || GoCD || GIT || GITHUB ||
4 年Well explained Hasti Vora ??