Introduction to GIT & GITHUB
What is Git?
Git can be defined as an open-source distributed version control system tool. It is free and can handle projects of virtually any size quickly and accurately. It owes its creation to Linus Torvalds, who did it in 2005 in the process of developing Linux Kernel. In terms of the core parameters needed for a tool, Git has it all: it is functional; it performs well, is secure and flexible. In other words, it has what is needed by most teams and individual developers.
Using Git, teams can work seamlessly and synchronously, with all the team members being able to use the same files.
Yet, Git can make all this happen without confusion at any user’s end when more than one person is working on the same files for editing.
There are many ways it can be set up and configured, but at my job, here’s how we use it: when a new employee starts, he downloads all the files from GitHub, which is an online service we’re all connected to.
- Version control software
Goals of GIT
What Are the Benefits of Git?
Git has several key benefits, some of which are these:
Historical Change Tracking – Git enables a user to review the history of their commits, that is, how they have changed. This is shown via a graph, with which the user can also analyze when these changes were made, and by whom. It is also possible to go back to a previous commit if necessary. The advantage of this kind of feature is that identifying and fixing bugs is a lot simpler.
Working as a Team – Git also makes it possible for a user to share the code with other members of the team so that they can validate it before committing or merging back to the main working branch. Additionally, the branching and review capabilities enable simultaneous development. Multiple people can work on the same file and resolve differences later.
Availability and Redundancy – Git being a distributed VCS, nothing is stored in a centralized, single location. This gives it the advantage of a distributed system, which is that backups are readily available whenever one needs them. Because of this feature, the user can work offline and then get online only to carry out the changes.
Git Is the Industry Standard – Git’s popularity has soared to such an extent that many integrated development environments (IDEs) and many popular developer tools including AWS Code Commit, Jenkins, and Travis support it. Git comes with several free resources, notable among which is the Git open-source page. For Git Basics and installation click Link.
What is GitHub?
Now, let us get an understanding of GitHub. Like Git, GitHub too, is an open-source platform. It is used for controlling the version and collaborating between software developers. GitHub took off from Git. It was started in 2008. It adapts the software as a service (SaaS) model for delivery.
Collaboration software, hosts GIT repositories
Repository to store the files/projects/code
Entire Linux code runs on GITHUB
Create a branch on master replica, as the changes should not be done on master
Master should always have to be deployable
Branch is exact copy of master
sort of making changes to branches.
Open pull request on GitHub
Comparing the change with master and show other people about your changes
People may give suggestions or go ahead
Commits the branch
Cloning is for making local copy from remote copy in GITHUB and working on a project
GITHUB is remote repository
Entire project can be copied to locally and work on it without internet access
Multiple people can work on GITHUB
When we push our changes to GitHub, other users can pull the request and see them
git clone https://github.com/username/repository
git branch feature-branch
git checkout feature branch
git add index.html
With every commit we make there will be Commit id
When the commit was made date and time (parent commit)
Before the commit what was the previous commit etc.
To clone the project
Create user id and password on the git hub site
Then create a new repository on GitHub
Then clone that repository using
Git clone https://github.com/jacksind/git.git
git config –global user. Email firstname.lastname@example.org
git config –global user.name admin
How to use git bash and workflow of git?
This below architecture will give brief idea how git repository will work.
If you understand the above diagram well and good, but if you don’t, you need not worry, I will be explaining these operations in this Git Tutorial one by one. Let us begin with the basic operations.
You need to install Git on your system first. If you need help with the installation, check this link to download and install https://git-scm.com/.
After installation Git in your system, just open your jack/directory where you want to store all your project files; right click and select ‘Git Bash here’. To learn more about Git workflow visit Link.
It will open git bash terminal and initialize git repository in the same folder.
Use git init command to create empty repository folder. Check screenshot below.
git init creates an empty Git repository or re-initializes an existing one. It basically creates a. git directory with sub directories and template files.
2. git add
Now the repository has initialized in folder. Create some sample files and add into git repository. By using command git add –all.
3. git status
The git status command lists all the modified files which are ready to be added to the local repository.
This will commit the staged snapshot and will launch a text editor prompting you for a commit message.
Use command — git commit -m “your message”
The git pull command fetches changes from a remote repository to a local repository. It merges upstream changes in your local repository, which is a common task in Git based collaborations.
Set your repository origin URL to connect and upload files into git hub. By using command “git remote add origin
git push origin master
This command will copy all the files from the master branch of remote repository to your local repository. We have created two files while pushing it will copy files from local repository to GitHub.
Now check central repository in GitHub, whether all files are push from local to GitHub. Check as below screenshot.
Yes, it did. 🙂 All files are copied from local t GitHub repository.
Staging is a step before the commit process in git. That is, a commit in git is performed in two steps: staging and actual commit. If a changeset is in the staging area, git allows you to edit it as you like (replace staged files with other versions of staged files, remove changes from staging, etc.)
Merging is Git’s way of putting a forked history back together again. The git merge command lets you take the independent lines of development created by git branch and integrate them into a single branch.
How to Integrate GIT with Jenkins?
1.Click on the Manage Jenkins button on your Jenkins dashboard:
2: Click on Manage Plugins:
3. Install GIT
- Select the GIT Plugin
- Click on Install without restart.
- If we need, we can select Download and Restart and after Installation click on check Now.
4. After Installing Git Plugin, we can see in right side click on “CREATE NEW ITEM”.
5. Now, we need enter our project Name “Jenkins”.
choose “Free style project”
6. open project and configure git repository under “source code management”. Add bitbucket or GitHub credentials to connect git hub Repository.
7. Build code and check console output. Whether the code is successful, and Jenkins able to connect with Git Hub.
DevOps is used for improving the SDLC process. It does this using many automation tools.
Git, on the other hand, is used mainly to control versions of codebase in DevOps.
Written by Jagadeesh