Basic Operations
| Command | Description |
|---|---|
git init | Initialize a new repository |
git clone <url> | Clone a repository |
git status | Check working directory status |
git add <file> | Stage a file |
git add . | Stage all changes |
git commit -m "message" | Create a commit |
git push | Push to remote |
git pull | Pull from remote |
Branch Operations
| Command | Description |
|---|---|
git branch | List branches |
git branch <name> | Create a new branch |
git checkout <branch> | Switch to a branch |
git checkout -b <name> | Create and switch to a new branch |
git merge <branch> | Merge a branch |
git branch -d <name> | Delete a branch |
History
| Command | Description |
|---|---|
git log | Show commit history |
git log --oneline | Show history in one line |
git log --graph | Show history as a graph |
git diff | Show differences |
git show <commit> | Show commit details |
Undo Operations
| Command | Description |
|---|---|
git reset HEAD <file> | Unstage a file |
git checkout -- <file> | Discard working directory changes |
git revert <commit> | Revert a commit (creates new commit) |
git reset --hard <commit> | Reset to a commit (dangerous) |
Remote Operations
| Command | Description |
|---|---|
git remote -v | List remotes |
git remote add <name> <url> | Add a remote |
git fetch | Fetch remote information |
git push -u origin <branch> | Push and set upstream branch |