Skip to content

Useful Git Commands

jhasenzahl edited this page Jun 13, 2012 · 12 revisions

Commands

git status - list changes since last commit
git add . - tracks any untracked files, and adds all modified files to next commit
git add . -A - same as above plus deleted files in local repository will also be deleted on the remote
git commit -a -m "Message" - automatically add and commit all modified files (does not add untracked files)
git merge [branch] - merges changes from a branch to the current branch (and auto-commits)
git push origin [branch] - pushes all commits on the working branch to a remote branch
git branch - lists all local branches
git branch [branch] - creates a local branch
git branch [branch] origin/[branch] - creates a local branch tracking a remote branch
git branch -d [branch] - deletes a local branch
git branch -D [branch] - force deletes a local branch, use with caution, may result in data loss
git checkout [branch] - change over to branch
git pull - get any changes from the remote and sync with your local repository


Example Usage

Merge a finished feature from joe-dev to develop

git checkout joe-dev
[do stuff here]
git add .
git commit -m "Implemented feature X"
git push origin joe-dev
git checkout develop
git merge joe-dev
git push origin develop

Clone this wiki locally