Git Fundamentals: Local Repository Setup and Distributed Version Control Workflows
Git operates as a distributed version control system where every workstation maintains a complete copy of the project history, contrasting with centralized architectures that rely on single server dependencies. This decentralized approach eliminates single points of failure and enables offline development capabilities.
Initialize a new repository by executing:
git init
This creates a .git mteadata directory containing version history. Enable hidden file visibility in your file manager to observe this directory.
Development occurs within the working tree—the visible directory containing editable files. After modifying source code, stage changes for commit:
git add README.md
For batch operations across multiple files:
git add src/app.js package.json docs/api.md
Or stage all modifications recursively:
git add .
Verify repository state using:
git status
Untracked or modified files appear highlighted in red. Successfully staged files display in green, indicating readiness for commit.
Persist staged changes to the repository history:
git commit -m "Implement user authentication module"
First-time Git installations require identity configuration before committing:
git config --global user.name "Alex Chen"
git config --global user.email "alex.chen@example.com"
After configuration, re-execute the commit command.
Establish connectivity with remote hosting services. Generate SSH credentials for secure authentication:
ssh-keygen -t ed25519 -C "alex.chen@example.com"
Accept default key storage loctaions by pressing Enter. Append the public key (located at ~/.ssh/id_ed25519.pub) to your hosting provider's SSH key management interface.
Link local repository to remote endpoint:
git remote add origin git@github.com:acme-corp/project-alpha.git
Upload local branches to remote servers. For initial pushes:
git push -u origin main
Subsequent updates require:
git push origin main
Team members acquire project code through cloning. After configuring personal SSH keys, execute:
git clone git@github.com:acme-corp/project-alpha.git
Synchronize local branches with remote changes:
git pull origin main
This command fetches and merges upstream modifications into your current working branch.