Git & Common Git Providers
A comprehensive guide to understanding and working with Git version control system.
Git Documentation
Welcome to the Git documentation. This guide will help you understand and work with Git version control system.
Table of Contents
Basic Commands
| Command | Description |
|---|---|
git init | Initialize a new Git repository |
git clone <url> | Clone a repository from remote source |
git add <file> | Add file(s) to staging area |
git add . | Add all modified files to staging area |
git commit -m "message" | Commit staged changes with a message |
git status | Show working tree status |
git log | Show commit history |
git diff | Show changes between commits, commit and working tree, etc. |
Branching and Merging
| Command | Description |
|---|---|
git branch | List all local branches |
git branch -a | List all branches (local and remote) |
git branch <branch-name> | Create a new branch |
git checkout <branch-name> | Switch to specified branch |
git checkout -b <branch-name> | Create and switch to a new branch |
git merge <branch-name> | Merge specified branch into current branch |
git branch -d <branch-name> | Delete a branch |
Remote Repositories
| Command | Description |
|---|---|
git remote -v | List all remote repositories |
git remote add <name> <url> | Add a new remote repository |
git push <remote> <branch> | Push branch to remote repository |
git pull <remote> <branch> | Pull changes from remote repository |
git fetch <remote> | Download objects and refs from remote |
Advanced Operations
| Command | Description |
|---|---|
git stash | Stash changes in working directory |
git stash pop | Apply stashed changes and remove from stash |
git reset --hard <commit> | Reset working directory to specified commit |
git rebase <branch> | Reapply commits on top of another base |
git cherry-pick <commit> | Apply changes from specific commit |
git tag <name> | Create a tag |
Configuration
| Command | Description |
|---|---|
git config --global user.name "Name" | Set global username |
git config --global user.email "email" | Set global email |
git config --list | List all configuration |
git config --global alias.<alias-name> <git-command> | Create command alias |
Common Workflows
Feature Branch Workflow
- Create a feature branch:
git checkout -b feature-name - Make changes and commit:
git add .andgit commit -m "message" - Push to remote:
git push origin feature-name - Create pull request (via web interface)
- After review, merge to main branch
Fixing Mistakes
- Amend last commit:
git commit --amend - Undo last commit (keeping changes):
git reset HEAD~1 - Discard all local changes:
git reset --hard - Discard changes to a file:
git checkout -- <file>
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.