Git Repository Basics
Understanding Git Version Control
Git is a distributed version control system designed to track changes in source code during software development. It enables multiple developers to collaborate efficiently by managing code modifications, branching, and merging.
Key Concepts of Git Repositories
Git repositories are storage spaces for project files and their complete version history. They can be local or remote, providing a comprehensive tracking mechanism for software development.
graph LR
A[Local Repository] --> B[Remote Repository]
B --> C[Collaboration]
C --> D[Code Management]
Repository Types and Initialization
Repository Type |
Description |
Initialization Command |
Local Repository |
Personal project space |
git init |
Remote Repository |
Shared project space |
git clone <repository-url> |
Creating a Git Repository in Ubuntu 22.04
## Create a new project directory
mkdir my-project
cd my-project
## Initialize a new Git repository
git init
## Configure user information
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
## Create initial project files
touch README.md
echo "## My Project" > README.md
## Stage and commit initial files
git add README.md
git commit -m "Initial project setup"
Basic Git Operations
Fundamental git operations include staging files, committing changes, and checking repository status:
## Check repository status
git status
## Stage specific files
git add filename.txt
## Stage all changes
git add .
## Commit changes with message
git commit -m "Descriptive commit message"
Repository State and Tracking
Git tracks file states through three main areas: working directory, staging area, and repository. Understanding these helps manage code effectively in version control workflows.