git command cheatsheet
git clone “email@example.com/reponame.git”
Clone an existing repository.
Create a new local git repository in the directory myproj.
Show changed files in the working directory.
Show difference of tracked files.
git diff –name-only HEAD~10 HEAD~5
Show the names of the changed files from between the tenth latest commit and the fifth latest
Stash the uncommitted local changes, stack them so they will be ignored during commit or merge. This is usually used when switch between branches.
git stash pop
Get the local changes that were stashed before back.
git add filename1 filename2 filename3…
Add file for the next commit.
git add .
Add all changed file for the next commit.
git commit -m “this is a comment for this commit”
Commit all the staged files which we did by git add.
git commit –ammend -m “This is a new message which will replace the message committed in the last commit”
Changes the commit message from the last commit.
Shows all commit history for the current working branch.
git log “branchname”
Shows all the commit history for the specified branchname.
git log -p “filename”
Shows all the commit history for the specified filename.
git blame “filename”
Shows who changed what and when in the specified filename.
git checkout -b projectOne origin/projectOne
Checkout out the projectOne branch from the remote and name it projectOne in your local git repository.
Lists all existing branches.
git branch -m old-branch-name new-branch-name
Change the branch name
git branch -m new-branch-name
Change the current working branch name
git checkout master
Switch the working directory to the master branch.
git checkout projectOne
Switch the working directory to the projectOne branch.
git branch “new branch name”
Create a new branch based on your current branch.
git push origin “branchname”
Push the specified branchname to the remote repository.
git branch -d “branchname”
Deletes the specified branchname.
git push origin :”branchname”
Deletes the specified branchname in the remote repository, which has to be followed by detleting the local repostory branch first.
git tag “tagname”
Create a tag based on the current working branch.
git push origin –tags
Pushes all the tags to the remote repository.
git tag -d “tagname”
Deletes the specified tagname.
git push origin :”tagname”
Deletes the specified tagname in the remote repository, which has to be followed by detleting the local repostory tag first.
git remote -v
Lists remote repostory addresses.
git remote show “remote address”
Shows information about the specified remote address.
Download all changes but not merge them.
Download all changes and merge them in to the current working branch.
git push origin “branchname”
Pushes the committed changed in the current working branch to the specified remote branch.
git merge “branchname”
Merges the specified branchname into the current working branch.
git cherry-pick “commit-number”
Merges the changes in the specified commit-number into the current working branch.The commit number can be from any branch.
git rm “filename”
Remotes the specified filename
git reset –soft HEAD^
Undo the last local commit, keep the changes.
git reset –hard HEAD^
Undo the last local commit, throw away the changes.
git reset –hard revision#
Revert back to the specified revision#.
Search within Codexpedia
Search the entire web