Git, GitHub, and Version Control
This is a complete guide for learning the git, GitHub, and git versions control.
Basically, What is Git Let us talk about this while starting this journey of learning.
Git:- It is distributed Control System. In other words, it is a way to keep track of all the versions of your Project and it can be used to collect and collaborate with other people.
There are 2 main features of git.
i) All version of Project
ii) Good For Collaboration
It is good for collaboration as well as for tracking of the history of your work so git is a program that exists locally on your computer.
Many People get Confused that git and GitHub are basically the same but it is a misunderstanding.
Difference Between Git and Github
They are two different things we mentioned, git is a program that exists on your computer while GitHub is a company that provides hosting for projects using git. Github provides you that you can host your Projects on a Remote Server.
In the nutshell, you can host your Projects that use git on Github.
For working on Github.com we create an account on it and host your projects
That is the difference between git and GitHub.
Using the terminal and Installing Git
Git has to install or pre-install but sometimes of low version. You may update it to the latest version
using the terminal we will perform the commands.
Terminal- It is a place where you can type in commands and make things happen on your computer or see the configuration
3. Setting up git:- while using the first time you have to set up the git username and email. Before starting the project setup mail and username in the user in the configuration file or setting file. This is important because you look at your project history you will want to know who made which changes
4. ls command:- It is a command that lists all the files in a folder.
5. ls -a command:- it is used to use the hidden files of the folder.
Git config file:-which tells about the user and e-mail
To use it write the command:-
git config --global <option> <value>
for example:- git config -- global user.name {username}
git config --global user.email {email}
Project Directory
A)mkdir <directory name>
Note:- we use “Camel Use” where we can’t use the space in between names and each first is a letter Capitalized.
mkdir Rocky Mental It will generate 2 different folders of it Named-Rocky and Mental.
B)Change Directory:- (command)(Cd)
cd-change directory cd<directory Name> means that go into this folder
To back out from the folder use (cd..) the command to back out.
C)Creating a repository
git init is a command for creating the repository which is a hidden file
D)Add a file to our Project
The content of our project folder and the files we find within it are represented by something called a working directory.
E)Working Directory is sort of like a workbench. It’s where you work on your files and you edit them you can add new files and you can delete files
.git folder:-It represents our repository.
The repository contains the staging area and commits History.
i)Staging Area:- It is sort of like a rough draft space. Whenever you are done working on the file in the working directory you want to add it to your staging area because once you have all the files in your staging area because once you have all the files you want in the next version of your project
ii)When you are ready to save them in the next version of the project called Commit.
iii)Commit-Basically a version of your project and each commit has a 40-character hash that is unique and has cat like a name to commit
Recommended by LinkedIn
iv)Commit History:- It is a way to refer to it so the comments are in something called commit history.
for adding a new file first is the working directory then the staging area then commit history
f)Git Status:- git status will tell us about the state of our working directory and our staging area. If there is a file that is not committed yet it shows as an untracked file.
g)git add <file> It copies a file from the working directory into the staging area.
After the git adds command it will create an index file which is known as a staging area.
Branch:-
In git default name of the branch is a master.
i)Making a branch
git branch:- master branch will be approached
ii)git branch <branch name>
iii)git log:- shows all the branches' point
iv)Head:- It is a pointer that is referred to the branch to which we pointed.
v)Switch Branches:-
git checkout<branch name>:- change the branch from master to <branch name>
if we do some changes in the branch it will not affect the master branch
vi)Merge a branch
vii)git merge <branch name> after this main and branch are merged
viii)git branch -d <branch name> delete the branch
ix)Vi or Vim:-
This is a text editor from normal mode where open the file and inverts mode we commit the message and then git status git commit and press “I” to insert and ESC key to exit with:wq to save and exit in edit mode.
Remote Repositories:-
It is the presence of a Repository on the server which contains a git file.
git local to git remote by 2 commands from local to remote push/clone
i)Adding a remote repository
ii)create a new repository
git remote add <remote name><url>
iii)Pushing to a remote repository
git push <remote Name><branch>
Remote tracking branches are local branching that tracks remote branches
iv)git push origin master (new branch and folder has created)
v)Updating a remote Repository:-
git add.
git commit -m “message”
git push origin master
git clone <url> <directory Name>(new folder with clone of repository)
vi)fetching changes
git fetch <remote>
git log-- remote
git merge origin/master
git pull <remote><branch>
git pull origin master(fetch all changes + merges)
git push origin master(shows the website of GitHub shows commit)
Handwritten Notes of Git are provided below just Click here