Deep Dive in Git & GitHub for DevOps Engineers.
What is Git and why is it important?
Git is a versional controlling system that is required to store the working of project flow on each build. Various components in git can be accessed with commands. Let's understand the complete process:
At first code is built by developer and saved on local machine, to keep the data for the code upto which point it is built we can move data to staging area with command
git add .
/git add <filename>
. By this the data is set to staging area and is ready to make a way to local repoNow after staging area comes commit to local repo. This stores all the history of versions in layman's it is the place where it is known what changes are made on which branch also timings. To commit we use
git commit -m "message for the commit"
. Now the log is made to local repo. If by a chance developer want's to get back to certain built of code he/she can easily access it from the commit logNow to store all these logs with code in safe place on cloud we use github that is remote repository. To put all the changes we set
git push
command that send all the logs of built along code to the remote repository.
What is difference Between Main Branch and Master Branch??
When we make a commit on local it is automatically made on main branch, but in case of remote repo is is called as master branch to which we are pushing the code. We can also change the name of branch and use them as per convenience. We can use
git branch
to check out which branch we are usingCan you explain the difference between Git and GitHub?
Git a tool to control versions where as github is a online repository store where can save our code and logs of versions and used for collaborations with teams and allow public to contribute.
Git is used in local system means the changes made as user are been visible in logs as for user, where as github is global store
How do you create a new repository on GitHub?
When we login to github there is option on right side of corder that has + sign as New repository click on it. A page will appear there we need to set information such as name for the remote repository, it's visiblity to keep it public or set as private. Include read me file or not which is optional but meant to be good practice to create one. Now click on to create repository and your remote repository is created.
What is difference between local & remote repository? How to connect local to remote?
Local repository is controlled by user with help of git that is version control system(distributed). All the changes made to code can be stored in form of logs in staged area of git in local machine which is thus called a local repository. Now to store all the code on remote store to make it accessible to other's for reasons such as to make it open source contributable or to store code in cloud. This all can be achieved with help of git commands
1. First after a code build adds to the local repo before that initialize git in local folder where the code is built with the command
git init
.Now use
git add .
command to store all the code in staging areaAnd then
git commit -m "message"
for storing it on the local repository as a version.Now on remote, we have to create a repository as explained above. Now to connect this remote repo to local we use the command
git remote add <git url>
This command will connect to the remote repo onto local.
Now use push command to push the commits of the local repository to the remote as
git push