#git
Chanchal Kumar Kharia
MCA, REDHAT, AWS, Network Infrastructure Management, IT Operations and administration
Git
Git is a VCS — Version Control System. It helps us manage our project files.
One of the primary things that git does and also the primary reason it exists is to keep track of the entire history of things that we are working on.
This is especially helpful in software development because when we are working on a project we first build a basic version of it and then try to improve it by adding new features (or) just experiment with things. This whole process of experimenting with new features is incredibly error prone and we might wanna revert back (Roll back) to our original code.
This is where Version Control comes into play, it automatically tracks every minute change in our project and allows us to revert back to a previous version no matter how many times we changed our files.
Another awesome thing that Git allows to do is, it allows people to work together on the same project at the same time without disturbing each other’s files. Collaboration is all the easier with Git. Team members can work on different features and easily merge changes.
GitHub
GitHub is a web-based service for version control using Git. Basically, it is a social networking site for developers. We can look at other people’s code, identify issues with their code and even propose changes. This also helps us in improving our code.
In short, Git is Version Control System and GitHub is a hosting service for Git Repositories.
Installation
Windows
Download and install Git for Windows. Once installed, we’ll be able to use Git from the command prompt or PowerShell.
Linux
Use your Linux package management system to install Git. on Ubuntu:
> sudo apt-get install git
Some Basic Terminology and Commands
Repository: A Git Repository, or a repo, is a folder that we have told Git to help us track file changes.
We can use this command to check status of git –
> git status
Git init (Initialize) – Now as this local repository created, git is keep on tracking my local working area.
Use the git init command to create a new repo from an existing folder on computer. From the command line, navigate to the root folder containing our code and run
> git init
with git add . move changes from the working directory to the staging area.
> git add .
Commit: A commit is a set of one or more changes to a file(or a set of files). Every time we save, it creates a unique ID(“hash”) which helps it keep track of the history.
git commitTakes the staged files and commits it to the project history. Together with git add, this saves our changes in the main repo.
> git commit -m "commit message"
Commit means the file is in local hard drive and after commiting it will be copied to git storage
Before commit we have to configure git first -
> git config --global user.name "user name"
> git config --global user.email "user email"
We can check git with below commands –
> git status
> ls
> git log (This will show Author Name and Commit ID)
Pushing to GitHub
>git push
It will fail because we have not linked git to github
To check remote location –
> git remote -v
To add remote location –
> git remote add mygit(origin) “URL” from github
Now run to check if it is set –
> git remote show mygit
It will show below message
HEAD branch (unknown)
First time we have to create one link in between git and github
> git push –set-upstream mygit master
(Copying from windows/mac – it doesn’t ask password every time because windows/mac stores password in credential manager)
(For linux we have to create a setup for password less (ssh-keygen)
Deployment (Operation Part)
- Settingup hardware and installing OS
- Setup environment for application (ex. Apache server)
Configuring/copying web page -
> git clone “URL” . /var/www/html
To restore previous code/file –
> git reset “CommitID” myfile.html
> git checkout --myfile.html
But all above process we have done is manually. We need something where everything done automatically.
We need to setup a tool that integrate continuously (IC) and the product is Jenkins.