What is Git And Git Hub..??
Rajni Shiv Kant
Digital Transformation | Ex-Tata Motors | Ex-Tata Steel | Automobile | Assembly Line | Steel | Rolling Mill | After Sales Support | Process & Systems
GitHub is a platform where you can host your code & can do version control in a dedicated or shared environment with your colleagues.
The “Git” in GitHub
To understand GitHub, you must first have an understanding of Git. Git is an open-source version control system that was started by Linus Torvalds—the same person who created Linux. Git is similar to other version control systems—Subversion, CVS, and Mercurial to name a few.
The “Hub” in GitHub
We’ve established that Git is a version control system, similar but better than the many alternatives available. So, what makes GitHub so special? Git is a command-line tool, but the center around which all things involving Git revolve is the hub—GitHub.com—where developers store their projects and network with like minded people.
Let’s go over a few of the main reasons that geeks like to use GitHub, and learn some terminology along the way.
Difference Between Git And GitHub
GitHub is a central repository and?cloud-based service?that allows developers to store and manage their code in the cloud, as well as track and control modifications.
Git is a free, open-source distributed?version control tool?that may be used for both small and big projects. Git was created to make it easier for programmers and developers to collaborate.
The Work Flow of GitHub
Cloud Based Hosting Services
Cloud hosting is a cloud delivery strategy that uses?Infrastructure as a Service (IaaS)?to provide a set of remote/virtual services. These services are provided on-demand and are hosted on a cloud computing infrastructure.?Full apps and development platforms, as well as servers, storage, and virtual desktops, are all available as cloud-based services.
What is a “version control system”??
Version control systems are a category of software tools that helps in recording changes made to files by keeping a track of modifications done to the code.
Why Version Control system is so Important?
As we know that a software product is developed in collaboration by a group of developers they might be located at different locations and each one of them contributes in some specific kind of functionality/features. So in order to contribute to the product, they made modifications in the source code(either by adding or removing). A version control system is a kind of software that helps the developer team to efficiently communicate and manage(track) all the changes that have been made to the source code along with the information like who made and what change has been made. A separate branch is created for every contributor who made the changes and the changes aren’t merged into the original source code unless all are analyzed as soon as the changes are green signalled they merged to the main source code. It not only keeps source code organized but also improves productivity by making the development process smooth.
Benefits of the version control system:
a)?Enhances the project development speed by providing efficient collaboration,
b)?Leverages the productivity, expedite product delivery, and skills of the employees through better communication and assistance,
c)?Reduce possibilities of errors and conflicts meanwhile project development through traceability to every small change,
d)?Employees or contributor of the project can contribute from anywhere irrespective of the different geographical locations through this?VCS,
e)?For each different contributor of the project a different working copy is maintained and not merged to the main file unless the working copy is validated. A most popular example is?Git, Helix core, Microsoft TFS,
f)?Helps in recovery in case of any disaster or contingent situation,
g)?Informs us about Who, What, When, Why changes have been made.
Forking a Repo
“Forking” is when you create a new project based off of another project that already exists. This is an amazing feature that vastly encourages the further development of programs and other projects. If you find a project on GitHub that you’d like to contribute to, you can fork the repo, make the changes you’d like, and release the revised project as a new repo. If the original repository that you forked to create your new project gets updated, you can easily add those updates to your current fork.
Social networking
The social networking aspect of GitHub is probably its most powerful feature, allowing projects to grow more than just about any of the other features offered. Each user on GitHub has their own profile that acts like a resume of sorts, showing your past work and contributions to other projects via pull requests.Project revisions can?be discussed publicly, so a mass of experts can contribute knowledge and collaborate to advance a project forward. Before the advent of GitHub, developers interested in contributing to a project would usually need to find some means of contacting the authors—probably by email—and then convince them that they can be trusted and their contribution is legit.
GitHub Isn’t Just for Developers
All this talk about how GitHub is ideal for programmers may have you believing that they are the only ones who will find it useful. Although it’s a lot less common, you can actually use GitHub for any types of files. If you have a team that is constantly making changes to a word document, for example,?you could use GitHub as your version control system. This practice isn’t common, since there are better alternatives in most cases, but it’s something to keep in mind.
What is Pulling And Pushing
Pull Requests
You’ve forked a repository, made a great revision to the project, and want it to be recognized by the original developers—maybe even included in the official project/repository. You can do so by creating a pull request. The authors of the original repository can see your work, and then choose whether or not to accept it into the official project. Whenever you issue a pull request, GitHub provides a perfect medium for you and the main project’s maintainer to communicate.
The git pull command downloads changes from a remote repository and saves them to a local repository. It combines changes from upstream into your local repository, which is a regular activity in Git-based collaborations. Developers use this command if a teammate has made commits to a branch on a remote, and they would like to reflect those changes in their local environment.
$ git remote add origin <central repository's link>
This command is used to make a central repository the origin.
$ git pull origin master
This command will copy all files from the remote repository's master branch to your local repository.
$ git pull origin <branch-name>
This command is used for pulling files from a different branch.
We can see that new branch has been made but "a.md" cannot be seen in master branch so what will do is "COMPARE AND PULL REQUEST" then "OPEN A PULL REQUEST" (that whatever code written in "a.md" will tell to compare and see if code is right.
Push
This command syncs commits between your local and remote repositories. Pull operation is the polar opposite of push operation. Pushing commits to distant repositories, whereas pulling imports commits to local repositories.
Git push is a command that pushes your local modifications to a central repository. When one has accumulated multiple local commits and is ready to share it with the rest of the team, use the following command to push them to the central repository:
$ git push <remote>
Note: When using the pull command, this remote refers to the remote repository that was previously configured.
This syncs the changes from the local repository to the remote repository, including all commits and internal objects. In the target repository, this generates a local branch.
$ git push origin master
This command is used to reflect the already committed files in the master branch of the central repository.
Git does not enable push when it results in a non-fast forward merging in the destination repository to prevent overwriting.
$ git push <remote> --force
Even if the push operation results in a non-fast forward merging, the above instruction forces it.?
Creating a new repository.
A repository (usually abbreviated to “repo”) is a location where all the files for a particular project are stored. Each project has?its own repo, and you can access it with a unique URL.
"git pull" to come back to origin/master - basically to update local branch.
Git Clone
What is the use of git clone and how to use it?
The?git clone?command is used to duplicate a repository or a branch inside a repository.
Git is a version control system that is distributed. By cloning, you may reap the benefits of having a whole repository on your own workstation.
git clone https://github.com/github/training-kit.git
When?one?clones?a?repository,?unlike?other?centralised?version?control?systems,?one?does not?obtain?a?single?file.?When?one?clones?a?repository?with?Git,?his/she?gets?the?complete?repository,?including?all?files,?branches,?and?commits.
领英推荐
Cloning?a?repository?is?usually?done?only?once,?at?the?start?of?a?project's?interaction?with?him. One would clone a repository that already exists on a remote, such as GitHub, so that one could interact with it locally. One would not need to clone a repository again to undertake normal development once he/she has cloned it.
All developers will be able to work more freely now that they have access to the complete repository. Working on a feature branch allows one to make changes without being constrained by the files one can work on.
?Most?common?uses?and?options of?git?clone:
$ git clone [url]
$ git clone --mirror
$ git clone --single-branch
$ git clone --sparse
$ git clone --recurse-submodules[=<pathspec]
Result?:
Use Command: "cd regex-git-internship/" then use command "git status"
Branch
What do you mean by Branch?
Working on multiple versions of a repository at the same time is known as branching.
Few common branch names used are:
A repository contains one main branch by default, which is considered the definitive branch. Branches are used to test and make changes before committing them to the main branch.
When one builds a branch off the main branch, he/she is essentially producing a replica of main as it was at the moment. One could pull in updates from the main branch if they were made while one was working on his/her branch.
Let's imagine you want to add a new feature (which is still in development), but you're unsure whether or not to make changes to your primary project. Branches allows one to switch back and forth between different project states/versions. In the example, one may establish a new branch and test the new feature without affecting the master branch. When finished, merge the changes from the new branch into the main branch. The master branch is the main branch in this case, which is present by default in your repository.
● Which branch should be used to keep deployment-ready code?
There is a?master/production branch?with a fresh branch for testing that is used to keep the deployment-ready code, as shown in the above figure. Two sets of changes are made under this branch, and once they are finished, they are merged back into the main branch.
● Create a new branch called development from the main branch.
We can use the?git branch?command to create, list branches on the command line.
$?git branch <branch name>
$ git branch developement
To create a new branch using the Git command line and to switch to the newly created branch, issue the command:
$?git checkout?<branch name>
$ git checkout developement
○?Checkout one more branch deployment from the previous branch.
$ git checkout -b deployement developement
○ Push different data into both branches.
$ git push origin developement
$ git push origin deployement
○ Merge data from both branches to the main branch.
$ git checkout developement
$ git merge main
A branch represents an independent line of development. Branches serve as an abstraction for the edit/stage/commit process. The?git branch?command lets you create, list, rename, and delete branches. It doesn’t let you switch between branches or put a forked history back together again. For this reason,?git branch?is tightly integrated with the?git checkout?and?git merge?commands.
git?branch
?
List all of the branches in your repository. This is synonymous with?git branch --list.
git?branch?<branch>
?
Create a new branch called?<branch>. This does?not?check out the new branch.
git?branch?-D?<branch>
?
Force delete the specified branch, even if it has unmerged changes. This is the command to use if you want to permanently throw away all of the commits associated with a particular line of development.
Branch A, Branch B and Branch C corresponds to Git Local Branches on a developer workstation. Mainline branch strategy is the simplest yet most effective strategy for small to medium sized teams.?The developers in the team constantly commit their work into a single, central branch—which is always in a deployment-ready state. In other words, the main branch for the project should only contain tested and quality work, and should never be broken.
Create a new branch called "development" from the main branch. checkout one more branch "deployment" from the previous branch. Push different data in both the branches. Merge data from both the branches to the main branch.
Now in Branch - Development will create another branch called "deployment" and will?push?a file in deployment branch and with pull request will merge contents of the both the branches -- "Development" & "Deployment"?
Now will create a?Pull request?to merge the content of both the branches "Development" & "Deployment". After merging will?delete the branch deployment?both from local and server. So at the end will be left with only 2 branches -- "Master Branch" [having all latest codes] and "Development Branch" [having codes ready to be released in a version]?
Click on -- "create pull request"
Click on "merge pull request"
Click on?"confirm merge"
As from the above image - we can see that the "deployment" branch has been successfully merged with the "development" branch will not click on -- "Delete Branch" as it will delete the branch "deployment" from the Git Repository.
Now to "DELETE" the branch "deployment" from the local machine, will use the following command line:
Will now make a?pull request?to merge the content of the branch "Development" with the "Master" branch
Click on "merge pull request"
Click on?"confirm merge"
As the branch "deployment" has now been deleted from both?local and server?will make changes in local machine already been done on server for the will use following command lines:
Steps To Ignore Files in Git | .gitignore file
.gitignore?file -- can be used to ignore specific file extensions from being included in git working copy.
For example -- While working on a specific folder, we created a test file by name -- "test.py" but have no intention to push it to the server. In that case .gitignore?file will come into picture.
As we write command "git status" Git Bash will show us one?Untracked file?which is?"test.py"
Now, In order to?ignore?this "test.py" file and avoiding it to?push it to the server?will now use .gitignore?command as follows:
Command: touch .gitignore -- this will create .gitignore folder?in the specified folder which we are working on.
Now will add?"test.py" file in .gitignore folder.
From the above image we can see that "test.py" file has been ignored and now it has been added in .gitignore folder.
IMPORTANT POINT TO REMEBER --?HAVE TO USE "git add .gitignore" in order to always track this folder if in future again if struck will some file/folder we wish to ignore.
After refreshing the GitHub Repository we can clearly see that test.py file has not been pushed and it has been clearly ignore with .gitignore folder
Sr. Project Manager-DATA | AWS Certified Solution Architect | SAFe POPM | CSM | PRINCE2 | ITIL
3 年Good article !!