20/03/2015 - GIT
Commands below are the most commonly used in daily working life. If you want to learn the best practises of branching model, make sure you read, understand and use git-flow cheatsheet and A successful Git branching model.
Stages only given file. git add
Stages all tracked and untracked files. git add
Stages all tracked and untracked files but ignores deleted files. git add
Stages all tracked files but ignores untracked files. git add
Commits all staged files. git commit
Merges given branch into current branch. git merge
Stashes all staged, tracked and untracked work in current branch. git stash
Brings back stashed work in current branch. git stash
Copies all indexed files in a branch and pastes into another branch with git stash apply
. git stash
Fetches changes of given commit into current branch. git cherry-pick
Renames branch. git branch
Undos changes and brings back deleted files in unstaged area. Files are removed from the working tree. Does not do anything to staged and untracked files. git checkout
Undos changes and brings back deleted files in unstaged area. Files are removed from the working tree. Does not do anything to staged and untracked files. git checkout
Undos changes to given file. File is removed from the working tree. Does not apply to untracked files. git checkout
Keeps the changes to given file and removes it from working tree. Does not apply to staged and untracked files. git update-index
Reverts what --assume-unchanged
does. Does not apply to staged and untracked files. git update-index
Copies given file from given branch into the current branch. git checkout
Deletes given branch from remote repository. git push
Removes untracked files from working tree and the file system. Does not apply to staged and tracked files. git clean
Removes untracked files and folders from working tree and the file system. Does not apply to staged and tracked files. git clean
Moves given file to untracked area by keeping the changes. File remains in file system. Flag -f
is needed to move 'new files'. Does not apply to untracked files. git rm
Removes given file from the file system and shows it in working tree. Does not apply to untracked files. git rm
Removes staged files and puts them back where they were before. Updates to files remain intact. git reset
Removes given staged file and puts it back where it was before. Updates to file remain intact. git reset
Goes "n" (1,2,3...) times back in commit history and puts all the files back in staged area. Updates to files remain intact including in next commits. e.g. If gone back to commit 1 from last commit which is 3 and recommit all again, git history will not show commit 2 and 3 because they are now in commit 1. git reset
Discards everything done in current branch. There is no going back to recover the loss. git reset
Goes "n" (1,2,3...) times back in commit history and discards everything done in given "n" branch (1,2,3). There is no going back to recover the loss. e.g. If gone back to commit 1 from last commit which is 3 there won't be anything in current working tree because everything has been discarded and git history will not show commit 2 and 3. git reset
Creates a new branch based on a given commit. The hash-id
above can be found with git reflog
command. git checkout
Creates a new branch based on a given commit. The hash-id
above can be found with git reflog
command. git branch
Returns the latest commit id/hash of "master" branch. git-ls-remote
Shows what a commit did. Outputs all changes line by line. git-show
Lists which files have been modified in a given commit. git-show
Show all changes to a file in all commits. The most recent is on top. git-log
Deletes given branch from remote repository. git-push
If you accidentally delete local copy of remote git information with rm -rf .git
or an any another way, you'll get "fatal: 'origin' does not appear to be a git repository" and "fatal: Could not read from remote repository" error when trying to push local changes to remote repository. This command solves that issue. git-remote
Unlike git log
, this shows only commit IDs and the messages. git-log
Prints git commit history as in graphical presentation.
List all commits that include a specific text in changes.