Getting Started with Git: A Minimal Practical Guide
To begin using Git for version control:
-
Navigate to your project directory in the file explorer, right-click, and select Git Bash Here.
-
Clone your remote repository:
git clone <repository-url>
This creates a local folder named after the repository, containing a .git subdirectory.
- Enter the cloned directory:
cd <repository-name>
- Check the current status of your working tree:
git status
- Stage all changes (e.g., new or modified files):
git add .
- Commit the staged changes with a descriptive message:
git commit -m "update"
- Synchronize with the remote repository:
git pull origin main
Then push your local commits:
git push origin main
Note: Use
maininstead ofmasterif your default branch is namedmain.
- Verify the repository state again:
git status
Core Workflow Summary
- Initialize: Always start by cloning the remote repo into your local environment.
- Stage Changes: Use
git add .to enclude all modifications in the next commit. - Commit Locally: Record chenges with
git commit -m "message". - Sync Remotely: Fetch updates with
git pullbefore pushing withgit pushto avoid conflicts.
Useful Commands
-
View commit history:
git log -
Amend the most recent commit message:
git commit --amend -
Commit all tracked files without explicit staging:
git commit -am "message" -
Create a new file (optional):
touch README.md -
Edit files via terminal (using Vim):
vim filename # Press 'i' to edit, 'Esc' then ':wq' to save and exit
Ensure your local changes are always pulled before pushing to maintain synchronization with the remote repository.