Git Repositories and Commits
Understanding Git Repositories
A Git repository is a container for a project's entire set of files, tracking complete version history and enabling collaborative development. Repositories can be local or remote, providing comprehensive version control capabilities.
Creating a New Repository
Initialize a new Git repository on Ubuntu 22.04 using these commands:
mkdir my-project
cd my-project
git init
Repository Types
Repository Type |
Description |
Local Repository |
Stored on your personal computer |
Remote Repository |
Hosted on platforms like GitHub |
Bare Repository |
Used for centralized collaboration |
Git Commit Workflow
graph LR
A[Working Directory] --> B[Staging Area]
B -->|git add| C[Staged Files]
C -->|git commit| D[Local Repository]
Making Commits
Demonstrate the commit process with a practical example:
## Create a sample file
echo "Hello, Git!" > README.md
## Stage the file
git add README.md
## Commit with a descriptive message
git commit -m "Initial project setup"
## View commit history
git log
Commit Anatomy
A Git commit contains:
- Unique identifier (hash)
- Author information
- Timestamp
- Commit message
- Pointer to previous commit
Tracking Project History
Explore repository history and changes:
## Show detailed commit log
git log --oneline --graph
## View file modifications
git diff
Version Tracking Strategies
Effective version tracking involves:
- Frequent, small commits
- Descriptive commit messages
- Logical branching
- Regular synchronization