Git For Beginners
Git For Beginners
A Comprehensive Guide
Part of AI Residency
Mohammad Arshad
Understanding the Need for Version Control
When you run , Git will create a hidden directory called in the
current directory. This directory contains all the Git
metadata, including the commit history, the branches, and
the configuration files.
Once you have initialized a Git repository, you can start adding
files to it and tracking their changes. To do this, you can use
the and commands.
Here is a simple example of how to use :
$ cd my-project
$ git init
This will create a new Git repository in the directory. You can
then add files to this repository and start tracking their
changes.
● git add: Adds files to the staging area, preparing them to be
committed.The command is a fundamental part of the Git
version control system. It is used to add files to the staging
area, which is a collection of files that are ready to be
committed to the repository. The staging area serves as a
temporary holding area where you can review and make
changes to the files before committing them.
● git commit: Commits the changes in the staging area to the
local repository, creating a new snapshot.The command in
Git is used to capture a snapshot of the changes made to
the tracked files in the staging area and save them as a new
revision in the local repository. It allows developers to record
the progress of their work, track changes over time, and
create a historical record of the project's evolution. Here's an
elaboration and expansion of the input text:
1. Staging Area:
○ The staging area, also known as the index, is a
temporary holding area where changes to tracked files
are stored before they are committed to the local
repository.
○ When you make changes to a tracked file, Git
automatically adds it to the staging area. You can also
manually add or remove files from the staging area
using commands like and .
2. Commit Message:
○ When you commit changes, you must provide a commit
message describing the changes made and the reason
for the commit.
○ The commit message serves as a concise explanation
of what was changed and why, making it easier to
understand the history and context of the project.
3. Local Repository:
○ The local repository is a directory on your computer
where Git stores all the project's files, including the
commit history, branches, and other metadata.
○ Committing changes saves the snapshot of the staged
changes into the local repository, creating a new
revision or version of the project.
4. Commit Object:
○ When you commit changes, Git creates a commit
object.
○ A commit object consists of the commit message, the
author and committer information, the timestamp, the
parent commit(s), and a reference to the tree object that
represents the snapshot of the files.
5. Commit History:
○ Each commit creates a new node in the commit graph,
which represents the project's history.
○ Navigating through the commit history allows
developers to trace the evolution of the project,
understand the sequence of changes, and identify
specific commits that introduced particular features or
bug fixes.
6. Branch Management:
○ Commits are associated with branches, which are
lightweight pointers to specific commits.
○ When you create a new branch, it starts from the
current commit of the branch you branched off from.
Committing changes on a branch creates new commits
on that branch.
Git push
Git push is a command in the Git distributed version control
system that is used to push local changes to a remote
repository. This allows you to share your changes with
others or to back up your work.
To use git push, you first need to have a remote repository set
up. This can be done using the git remote add command.
Once you have a remote repository set up, you can push
your changes to it using the git push command.
The git push command takes two arguments:
To force push your changes, you can use the following command:
git push origin master --force
The git push command is a powerful tool that can be used to
share your changes with others and to back up your work.
However, it is important to use it with care, as it can also be
used to overwrite other people's changes.
git pull:
Fetching:
● git status: Displays the status of the working tree and the
staging area, indicating any uncommitted changes.
Installation:
Conclusion
AI RESIDENCY
PROGRAM
6 MONTHS
ONE ON ONE MENTORSHIP
20 MASTER CLASSES
Community Profile
nas.io/aiguild