Back to Resources
Git Commands
A quick reference for the most commonly used Git commands for version control and collaboration.
| Command | Description | Usage |
|---|---|---|
| git init | Initializes a new local Git repository in the current directory. | git init |
| git clone | Copies an existing remote repository to your local machine. | git clone <repository_url> |
| git add | Adds changes from the working directory to the staging area. | git add <file> or . |
| git status | Shows the status of changes: what's staged, what isn't, and which files aren't being tracked. | git status |
| git commit | Saves a snapshot of the staged changes to the repository's history. | git commit -m "Commit message" |
| git push | Sends your local commits to the remote repository. | git push origin <branch_name> |
| git pull | Fetches and downloads changes from a remote repository and updates the local branch. | git pull origin <branch_name> |
| git branch | Lists, creates, or deletes branches. | git branch <new_branch> |
| git checkout | Switches to another branch or restores files from the working tree. | git checkout <branch_name> |
| git merge | Merges a different branch into your current active branch. | git merge <branch_to_merge> |
| git log | Shows the commit history for the current branch. | git log |
| git remote | Manages the set of tracked repositories (remotes). | git remote -v |
| git diff | Shows the differences between commits, commit and working tree, etc. | git diff |
| git stash | Temporarily shelves modified, staged changes to work on something else. | git stash |