GIT CREATE
Clone an existing repository
1 |
$ git clone ssh://user@domain.com/repo.git |
Create a new local repository
1 |
$ git init |
LOCAL CHANGES
View Changed files in your working directory
1 |
$ git status |
View Changes to tracked files
1 |
$ git diff |
To Add all current changes to the next commit
1 |
$ git add . |
To Add some changes in <file> to the next commit
1 |
$ git add -p <file> |
Commit all local changes in tracked files
1 |
$ git commit -a |
Commit previously staged changes
1 |
$ git commit |
Change the last commit
Don‘t amend published commits!
1 |
$ git commit --amend |
COMMIT HISTORY
Show all commits, starting with newest
1 |
$ git log |
Show changes over time for a specific file
1 |
$ git log -p <file> |
Who changed what and when in <file>
1 |
$ git blame <file> |
BRANCHES & TAGS
List all existing branches
1 |
$ git branch -av |
Switch HEAD branch
1 |
$ git checkout <branch> |
Create a new branch based
on your current HEAD
1 |
$ git branch <new-branch> |
Create a new tracking branch based on a remote branch
1 |
$ git checkout --track <remote/branch> |
Delete a local branch
1 |
$ git branch -d <branch> |
Mark the current commit with a tag
1 |
$ git tag <tag-name> |
UPDATE & PUBLISH
List all currently configured remotes
1 |
$ git remote -v |
Show information about a remote
1 |
$ git remote show <remote> |
Add new remote repository, named <remote>
1 |
$ git remote add <shortname> <url> |
Download all changes from <remote>,
but don‘t integrate into HEAD
1 |
$ git fetch <remote> |
Download changes and directly merge/integrate into HEAD
1 |
$ git pull <remote> <branch> |
Publish local changes on a remote
1 |
$ git push <remote> <branch> |
Delete a branch on the remote
1 |
$ git branch -dr <remote/branch> |
Publish your tag s
1 |
$ git push --tags |
MERGE & REBASE
Merge <branch> into your current HEAD
1 |
$ git merge <branch> |
Rebase your current HEAD onto <branch>
Don‘t rebase published commits!
1 |
$ git rebase <branch> |
Abort a rebase
1 |
$ git rebase --abort |
Continue a rebase after resolving conflicts
1 |
$ git rebase --continue |
Use your configured merge tool to
solve conflicts
1 |
$ git mergetool |
Use your editor to manually solve conflicts and (after resolving) mark file as resolved
1 |
$ git add <resolved-file> |
1 |
$ git rm <resolved-file> |
UNDO
Discard all local changes in your working directory
1 |
$ git reset --hard HEAD |
Discard local changes in a specific file
1 |
$ git checkout HEAD <file> |
Revert a commit (by producing a new commit with contrary changes)
1 |
$ git revert <commit> |
Reset your HEAD pointer to a previous commit and discard all changes since then
1 |
$ git reset --hard <commit> |
preserve all changes as unstaged changes
1 |
$ git reset <commit> |
preserve uncommitted local changes
1 |
$ git reset --keep <commit> |