33
loading...
This website collects cookies to deliver better user experience
Git
is an Open Source Distributed Version Control System.Git
is a content tracker. So Git
can be used to store content — it is mostly used to store code due to the other features it provides.Git
keeps changing as more code is added. Also, many developers can add code in parallel. So Version Control System
helps in handling this by maintaining a history of what changes have happened. Also, Git
provides features like branches and merges, which I will be covering later.Git
has a remote repository which is stored in a server and a local repository which is stored in the computer of each developer. This means that the code is not just stored in a central server, but the full copy of the code is present in all the developers’ computers. Git is a Distributed Version Control System
since the code is present in every developer’s computer.NB:Mac users can install it with brew: brew install git
git --version
# git version 2.31.0.windows.1
Git
know who you are. This is important for version control systems, as each Git
commit uses this information:git config --global user.name "James Brown"
git config --global user.email "[email protected]"
Note: Use global
to set the username and e-mail for every repository on your computer.If you want to set the username/e-mail for just the current repo, you can remove global
git config --global --list
mkdir myproject
cd myproject
mkdir
makes a new directory.cd
changes the current working directory.Note: If you already have a folder/directory you would like to use for Git: Navigate to it in command line, or open it in your file explorer, right-click and select "Git Bash here"
git init
Initialized empty Git repository in /Users/user/myproject/.git/
Note: Git now knows that it should watch the folder you initiated it on.Git creates a hidden folder to keep track of changes.
<!DOCTYPE html>
<html>
<head>
<title>Getting Started with Git!</title>
</head>
<body>
<h1>Hello world!</h1>
<p>This is the first file in my new Git Repo.</p>
</body>
</html>
index.html
.ls
index.html
ls
will list the files in the directory. We can see that index.html
is there.status
and see if it is a part of our repo:git status
On branch master
No commits yet
Untracked files:
(use "git add ..." to include in what will be committed)
index.html
nothing added to commit but untracked files present (use "git add" to track)
aware
of the file, but has not added
it to our repository!Staged
files are files that are ready to be committed
to the repository you are working on. You will learn more about commit
shortly.git add index.html
Staged
. Let's check the status:git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached ..." to unstage)
new file: index.html
commit
.stage
to commit
for our repo(folder) now that we have completed our work.git commit -m "My First git commit"
[master (root-commit) c7da65d] My first git commit
1 file changed, 12 insertions(+)
create mode 100644 index.html
commit
command performs a commit, and the -m "message"
adds a message.git log
commit c7da65d981ce205dfadbeedec4e36a5e1625c558 (HEAD -> master)
Author: jamesbrown <[email protected]>
Date: Mon Jul 12 17:34:54 2021 -0700
My first git commit