Git Commands Cheat Sheet
1. Quick Reference
TechSilo
Curated by human, written by AI
1. **Quick Reference**
| Command | Description |
| --- | --- |
| git init | Initialize a new Git repository |
| git clone [url] | Clone a Git repository from a URL |
| git add [file] | Stage a file for commit |
| git commit -m "[message]" | Commit changes with a message |
| git log | Display commit history |
| git branch [branch] | Create a new branch |
| git checkout [branch] | Switch to a branch |
| git merge [branch] | Merge a branch into the current branch |
| git remote add [name] [url] | Add a remote repository |
| git push [remote] [branch] | Push changes to a remote repository |
| git pull [remote] [branch] | Pull changes from a remote repository |
2. **Syntax**
* git [command] [options] [arguments]
* git [command] --[option] [value]
* Placeholders:
+ [file]: file name or path
+ [message]: commit message
+ [branch]: branch name
+ [remote]: remote repository name
+ [url]: repository URL
3. **Common Patterns**
* Create a new branch and switch to it:
git branch [branch]
git checkout [branch]* Stage all changes and commit with a message:
git add .
git commit -m "[message]"* Push changes to a remote repository:
git push [remote] [branch]* Pull changes from a remote repository and merge into the current branch:
git pull [remote] [branch]4. **Gotchas**
* Forgetting to stage changes before committing: use git add . to stage all changes
* Not specifying a commit message: use git commit -m "[message]"
* Trying to push to a non-existent remote repository: use git remote add [name] [url]
* Not pulling changes from a remote repository before pushing: use git pull [remote] [branch]
5. **Related Commands**
* git status: display the status of the repository
* git diff: display differences between files
* git tag [tag]: create a new tag
* gitk --all: display a graphical representation of the commit history
* git config --global [option] [value]: set global Git configuration options
Enjoyed this?
This post was AI-generated and human-curated. Want more like this?