What is Git?
Git is the most popular version-control system. There are other version-control systems such as Subversion.
What is version-control system?
It saves -
What changes was made to the source code?
Who made the changes?
When was the changes made?
Why we use a version-control system?
If an error was introduced to the source code, we can go to a previous version of code which did not have that error.
If many people are working on the same source code, we can manage who makes what changes to the code.
Download and Update Git
Download: Git - Downloads (git-scm.com)
Update:
git clone https://github.com/git/git
(Terminal Command)
Start Git
Run
git init
This will create a folder: .git
This is where history is saved.
Git Commands
git status
: See what items are untracked/staged.Untracked: Item is not on staging area.
- Staging Area: Git can only process items on the staging area. Items must be put on the staging area before any work can be done.
Staged: Item is in staging area.
git add .
: Add items to the staging area'.' means all items in the current directory.
Replace '.' with folder name to stage a particular item.
git commit -m "message"
: Store items in staging area to history.git restore --staged .
: Remove item from staging area to untracked.git log
: See history.git reset fea46a6ef9c48a621b941cf04802930f8635e480
: Go back to a particular commit. All commits have a code associated with it which can be seen whengit log
is run.