Skip to content

Instantly share code, notes, and snippets.

@joaovissoci
Forked from rpietro/git_commands.txt
Created December 12, 2013 02:36
Show Gist options
  • Save joaovissoci/7922381 to your computer and use it in GitHub Desktop.
Save joaovissoci/7922381 to your computer and use it in GitHub Desktop.
# all commands from http://git-scm.com/book
### Frequently used
#Clone repo
git clone LINK to REPO
#Commit changes
git commit -m 'comment'
git push origin master
### Regular commands
git status
git add --all
git commit -m/ 'comment'
git pull
git push
git diff # compares what is changed against what is staged
git diff --staged # compares staged changes against last commit
git commit -m "comment"
git commit -a -m 'comment' #skips staging
git rm file.txt #stages file removal
git rm --cached file.txt #keep the file in the working tree but remove it from the staging area, similar to what a .gitignore file would do
git mv file1.txt file2.txt # renames a file
# command above is equivalent to
mv file1.txt file2.txt
$ git rm file1.txt
$ git add file2.txt
git log
git log -p -2 # shows the diff introduced in each commit, limits it to the last two entries
git log -U1 --word-diff # get word diff instead of normal line by line diff, useful for markdown files
git log --stat #abbreviated stats for each commit
git log --pretty=oneline #prints each commit on a single line, short, full, and fuller options show the output in roughly the same format but with less or more information
git log --pretty=oneline
git log --pretty=format:"%h - %an, %ar : %s"
# Option Description of Output
# %H Commit hash
# %h Abbreviated commit hash
# %T Tree hash
# %t Abbreviated tree hash
# %P Parent hashes
# %p Abbreviated parent hashes
# %an Author name
# %ae Author e-mail
# %ad Author date (format respects the --date= option)
# %ar Author date, relative
# %cn Committer name
# %ce Committer email
# %cd Committer date
# %cr Committer date, relative
# %s Subject
git log --pretty=format:"%h %s" --graph #ASCII graph showing branch and merge history
# -p Show the patch introduced with each commit.
# --word-diff Show the patch in a word diff format.
# --stat Show statistics for files modified in each commit.
# --shortstat Display only the changed/insertions/deletions line from the --stat command.
# --name-only Show the list of files modified after the commit information.
# --name-status Show the list of files affected with added/modified/deleted information as well.
# --abbrev-commit Show only the first few characters of the SHA-1 checksum instead of all 40.
# --relative-date Display the date in a relative format (for example, “2 weeks ago”) instead of using the full date format.
# --graph Display an ASCII graph of the branch and merge history beside the log output.
# --pretty Show commits in an alternate format. Options include oneline, short, full, fuller, and format (where you specify your own format).
# --oneline A convenience option short for --pretty=oneline --abbrev-commit.
git log --since=2.weeks
# -(n) Show only the last n commits
# --since, --after Limit the commits to those made after the specified date.
# --until, --before Limit the commits to those made before the specified date.
# --author Only show commits in which the author entry matches the specified string.
# --committer Only show commits in which the committer entry matches the specified string.
git log --pretty="%h - %s" --author=gitster --since="2008-10-01" \
--before="2008-11-01" --no-merges -- t/ #narrows down to a very specific subset
git commit --amend # commit, add another file and then ammend to make it part of the previous commit, making it a single commit
git reset HEAD file.txt # added file.txt then reset will unstage it
git checkout -- file.txt # changes to a file are reverted, **dangerous command**
git remote -v # will show remote, verbose mode, but can only push to an ssh url
git remote add pb git://github.com/paulboone/ticgit.git # adding a remote, pb is the shortname assigned to that remote
git fetch [remote-name] # to fetch from a specific remote
git pull # automatically fetches and merges, git clone command automatically sets up your local master branch to track the remote master branch on the server you cloned from (assuming the remote has a master branch)
git push origin master # git push [remote-name] [branch-name]
git remote show origin # shows remote repository as well as the tracking branch information
git remote rename pb paul
git remote rm paul
# check where i stopped in the book
## branching
git branch testing # creates a new pointer at the same commit currently on, which is indicated by the HEAD pointer
git checkout testing # switches over to the testing branch
git checkout master # back to master
git checkout -b testing2 # creates branch and switches to it at the same time
# do some changes on the testing2 branch
git checkout master # back to master
git merge testing2 # merge testing2 into master
git branch -d testing2 # deletes testing2 branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment