What is Git and why is it needed?
Git is a command line utility for tracking and maintaining the change history of files in your project. Most often it is used for code, but it can be used for other files as well. For example, for pictures - useful for designers.
With Git, you can rollback your project to an older version, compare, analyze, or commit your changes to the repository.
A repository is the repository of your code and the history of its changes. Git runs locally and all your repositories are stored in specific folders on your hard drive.
Also, your repositories can be stored on the Internet. Usually, three services are used for this:
Each savepoint of your project is named a commit. Each commit has a hash (unique id) and a comment. A branch is built from such commits. A branch is a history of changes. Each branch has its own name. A repository can contain several branches that are created from or merged into other branches.
How does it work
If you look at the picture, it becomes a little easier with understanding. Each circle is a commit. The arrows show the direction from which the next commit is made. For example C3
made from 2
, etc. All of these commits are in a branch called main
. This is the main branch, most often called master
. The rectangle main*
shows which commit we are currently in, in other words, a pointer.
The result is a very simple graph consisting of one branch ( main
) and four commits. All this can turn into a more complex graph, consisting of several branches that merge into one.
We will talk about this in the following articles. First, let's analyze the work with one branch.
Installation
Git- /. , , (, ..). .
, Git.
# Homebrew
brew install git
# , .
git --version
# , Command Line Tools (CLT).
# . CLT git
Linux. .
# Debian Ubuntu
sudo apt install git
# CentOS
sudo yum install git
Git . , commit, , .
(Linux MacOS) (Windows) .
#
# <_> , , Grisha_Popov
#
git config — global user.name "<_>"
# email. .
git config — global user.email "<_@email.com>"
Git .
. .
# Linux MacOS /Users/UserName/Desktop/MyProject
# Windows ://MyProject
cd <___>
#/
git init
Git . , . commit.
# commit
git add .
#
git add - all
#
git add <_>
# commit. .
#
git commit -m "<>"
. commit.
Git
commit. , :
. , , .
, Git. .
Git. :
. .
GitHub
, Visual Studio Code (VS Code).
, . , .
VS Code .
JavaScript PHP
,
Git-
, ,
index.html
. .!
Tab
. HTML .ctrl+s
.
Git-.
:
GitHub
1
, ....public repository
,
Initialize Repository
. , .
, " GitHub " ( 2), , commit. ,
. GitHub, .
GitHub.
. , - , crtl+s
(Windows) cmd+s
(MacOS), . Git.
Git, 1 . , . :
. ,
commit
commit
commit GitHub
, commit GitHub!
Git. :
commit
VS Code, GitHub
, , :
git help #
git clone
git status
git branch
git checkout
git merge
git remote
git fetch
git push
git pull
P.S. , Git.
https://learngitbranching.js.org/
In the Step by Step telegram channel , I publish even more material and conduct educational streams for everyone.