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 branch0
Merges branch0 into the current branch (and auto-commits).

git push origin branch0
Pushes all commits of the current local branch to remote branch0.

git branch
Lists all local branches.

git branch branch0
Creates local branch0

git branch branch0 origin/branch1
Creates local branch0 tracking remote branch1 (they usually will have the same name).

git branch -d branch0
Deletes local branch0.

git branch -D branch0
Force deletes local branch0. Use with caution, may result in data loss.

git checkout branch0
Switch over to branch0.

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
[do stuff here]
git add .: Add all modified files to next commit
git commit -m "Implemented feature X": Commit all added files
git push origin joe-dev: Sync local commits with the remote branch joe-dev
git checkout develop: Switch over to the develop branch
git merge joe-dev: Merge the new stuff from joe-dev
git push origin develop: Sync local merge with the remote branch develop


Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

Clone this wiki locally