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 -m "Message"
Commit all added files, if git add was used.

git commit -a -m "Message"
Automatically add and commit all modified files. Unlike git add ., will not track untracked files.

git merge _branch_: merges branch into the current branch (and auto-commits)
git push origin _branch_ - pushes all commits of the current local branch to remote branch
git branch - lists all local branches
git branch _branch_ - creates local branch
git branch _branch1_ origin/_branch2_ - creates local branch1 tracking remote branch2 (they usually will have the same name)
git branch -d _branch_ - deletes local branch
git branch -D _branch_ - force deletes 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 to develop

git checkout joe-dev

switch to joe-dev branch

asd [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