Help
Get Help for Specific Command
git <command> --help
Moving Repositories
Initialize a Repo
git init
- Turns your current directory into a brand-new Git repository.
Clone a Repo
git clone <url>
- Downloads an existing repository from a remote source to your computer.
Commits & Staging
Check Status of Repo
git status
- Shows which files have been modified, which are being tracked, and what is currently in your staging area.
Add Files to Staging
git add <file-name>
- Moves changes from your working directory to the staging area. Use
git add .to add everything.
Commit Changes
git commit -m "Your descriptive message"
- Takes everything in your staging area and saves it as a permanent snapshot in your local history.
Branches
Manage Branches
git branch
- Lists all local branches. Adding a name after it creates a new branch.
Create New Branch
git branch <branch-name>
- Creates a new branch.
Switch Branches
git checkout <branch-name>
git switch <branch-name>
- Switches your current working environment to a different branch.
Pull Updates
git pull
- Fetches updates from the remote repository and immediately merges them into your current local branch.
History
View History
git log
- Displays a chronological list of all the commits made in the repository.
Example of a Git Workflow
Initialize Local Repo
cd /path/to/your/repo
git init
- This tells Git to start tracking the folder.
- It creates a hidden
.gitdirectory to track history.
Stage the Files
git add <path-or-folder>
- This moves your files into the staging area.
- Use
git add .to stage everything.
Create First Snapshot
git commit -m "Initial commit"
- This locks your files into local history with a message.
Link to the Existing Remote Repo
git remote add origin https://github.com/your-org/your-repo.git
- This tells Git where the remote repository lives (GitHub, GitLab, etc.).
Sync and Push
git pull origin main --rebase
- If the remote repo already has files (like a README), pull first to avoid clashing histories.
- If your default branch is named
masterinstead ofmain, use that instead.
Push Your Work
git push -u origin main
- The
-uflag creates a permanent link between your local branch and the remote one. - In the future, you’ll only need to type
git push.