View on GitHub

git-cheat-sheet

An overview of Git's most common commands, and related notes (such as high-level architecture)

< home < toolbox

The Daily Routine

Command Action
git pull Pull all remote changes from current branch
git checkout -b [branch-name-here] Create a new branch, from the current branch, for your bug/feature/issue
git add . Add any changed files to the staging index
git status See the current status of the workspace
git diff [source branch] [target branch] Show changes
git commit -m "Detailed message here" Make the commit have a nice, detailed message
git push Push your changes onto the current branch
git request-pull master ./ Request review of latest changes in current branch compared to master
git checkout master Switch back to the master branch when the feature is done and tested
git merge [branch-name-here] Merge all changes from the specified branch into the master branch
git push Push your merged changes onto the master branch

Additional Actions

Command Action
git init Initialize the current folder as a repository
git clone [/path/to/repo] Clone local repository
git clone [url] Clone a remote repository
git rm [file] Remove/delete a file
git push origin [branch] Push changes to a specific branch
git branch -d [branch-name-here] Delete a branch
git tag [tag] [commit ID] Create a tag
git log Display the git log
git checkout -- [filename] Restore working copy with latest from HEAD
git revert [commit ID] Rollback to the specified commit (preferred method for reverting a change)
git reset --soft [HEAD or commit ID] Discarding intervening commits.
Reset the HEAD to another commit but do not alter the index or working directory.
All changes between original HEAD and commit will be staged.
git reset --mixed [HEAD or commit ID] Discarding intervening commits and adds.
Reset the HEAD and index to another commit but do not alter the working directory.
All staged changes are removed from the index.
git reset --hard [HEAD or commit ID] Discarding intervening commits, adds and changes to files in local worksapce.
Reset the HEAD, index and workspace to another commit.
All changes between original HEAD and commit will be staged
Avoid using with shared repos.
git commit --amend Allow the message for the most recent commit to be edited
git rebase [branch-name] Similar to merge but more dangerous in shared repos. Appends the current branch to the specified branch. Main advantage is cleaner history.
git clean -n Perform a dry run of clean
git clean --force Clean all untracked files in the workspace
git clean --force -d Clean all untracked files and directories in the workspace
git clean --force -dx Clean all untracked and ignored files and directories in the workspace

 

 

 


Move along; nothing to see here…