the phrygian cap



Ohloh profile for Luis de Bethencourt

<Octubre 2017
Lu Ma Mi Ju Vi Sa Do
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
29 30 31        

Creative Commons License

planet gnome
planet ubuntu
alberto ruiz
andy wingo
jeff fortin
slomo's blog
jan schmidt
vincent's random waffle

"all religions, arts and sciences are branches of the same tree. all these aspirations are directed toward ennobling man's life, lifting it from the sphere of mere physical existence and leading the individual towards freedom." albert einstein

Git Cheat Sheet

A few weeks ago I created this Git Cheat Sheet as a reference for commands I use at least once a month. I've found it useful and I'm sharing it so others find it useful too. There are also markdown and org-mode versions available.

  • Configure
    • git config –global "[name]"
      • Sets the name you want attached to your commit transactions
    • git config –global "[email address]"
      • Sets the email you want attached to your commit transactions
    • git config –global color.ui auto
      • Enables helpful colorization of command line output
    • git config –global push.default current
      • Update a branch with the same name as current branch if no refspec is given
    • git config –global core.editor [editor]
      • Which editor to use when commit and tag that lets you edit messages
    • git config –global diff.tool [tool]
      • Specify which command to invoke as the specified tool for git difftool

  • Create repositories
    • git init [project-name]
      • Creates a new local repository with the specified name
    • git clone [url]
      • Downloads a project nd its entire version history

  • Make changes
    • git status
      • Lists all new or modified files to be committed
    • git status -s
      • Short view of status
    • git diff
      • Shows file differences not yet staged
    • git add [file]
      • Snapshots the file in preparation for versioning
    • git add .
      • Add all modified files to be commited
    • git add '*.txt'
      • Add only certain files
    • git add –patch filename.x (or -p for short)
      • Snapshot only chunks of a file
    • git rm [file]
      • Tell git not to track the file anymore
    • git diff –staged
      • Show what has been added to the index via git add but not yet committed
    • git diff HEAD
      • Shows what has changed since the last commit.
    • git diff HEAD^
      • Shows what has changed since the commit before the latest commit
    • git diff [branch]
      • Compare current branch to some other branch
    • git difftool -d
      • Same as diff, but opens changes via difftool that you have configured
    • git difftool -d master..
      • See only changes made in the current branch
    • git diff –no-commit-id –name-only –no-merges origin/master…
      • See only the file names that has changed in current branch
    • git diff –stat
      • See statistics on what files have changed and how
    • git reset [file]
      • Unstages the file, but preserves its contents
    • git commit
      • Record changes to git. Default editor will open for a commit message
    • git commit -m "[descriptive message]"
      • Records file snapshots permanently in version history
    • git commit –amend
      • Changing the history, of the HEAD commit

  • Group changes
    • git branch
      • Lists all local branches in the current directory
    • git branch [branch-name]
      • Create a new branch
    • git checkout [branch-name]
      • Switches to the specified branch and updates the working directory
    • git checkout -b <name> <remote>/<branch>
      • Switches to a remote branch
    • git checkout [filename]
      • Return file to it's previous version, if it hasn’t been staged yet
    • git merge [branch]
      • Combines the specified branch's history into the current branch
    • git merge –no–ff [branch]
      • Merge branch without fast forwarding
    • git branch -a
      • See the full list of local and remote branches
    • git branch -d [branch]
      • Deletes the specified branch
    • git branch -D [branch]
      • Hard branch delete, will not complain
    • git branch -m <oldname> <newname>
      • Rename a branch

  • Refactor filenames
    • git rm [file]
      • Deletes the file from the working directory and stages the deletion
    • git rm –cached [file]
      • Removes the file from version control but preserves the file locally
    • git mv [file-original] [file-renamed]
      • Changes the file name and prepares it for commit

  • Suppress tracking
    • .gitignore
      • *.log
      • build/
      • temp-*
      • A text file named .gitignore suppresses accidental versioning of files and paths matching the specified patterns
    • git ls-files –other –ignored –exclude-standard
      • Lists all ignored files in this project

  • Save fragments
    • git stash
      • Temporarily stores all modified tracked files
    • git stash pop
      • Restores the most recently stashed files
    • git stash list
      • Lists all stashed changesets
    • git stash drop
      • Discards the most recently stashed changeset

  • Review history
    • git log
      • Lists version history for the current branch
    • git log –follow [file]
      • Lists version history for a file, including renames
    • git log –pretty=format:"%h %s" –graph
      • Pretty commit view, you can customize it as much as you want
    • git log –author='Name' –after={1.week.ago} –pretty=oneline –abbrev-commit
      • See what the author has worked on in the last week
    • git log –no-merges master..
      • See only changes in this branch
    • git diff [file-branch]…[second-branch]
      • Shows content differences between two branches
    • git show [commit]
      • Outputs metadata and content changes of the specified commit

  • Redo commits
    • git reset
      • Unstage pending changes, the changes will still remain on file system
    • git reset [commit/tag]
      • Undoes all commits after [commit], preserving changes locally
    • git reset –hard [commit]
      • Discards all history and changes back to the specified commit

  • Synchronize changes
    • git fetch [bookmark]
      • Downloads all history from the repository bookmark
    • git fetch -p
      • Update history of remote branches, you can fetch and purge
    • git merge [bookmark]/[branch]
      • Combines bookmark's branch into current local branch
    • git push
      • Push current branch to remote branch
    • git push [remote] [branch]
      • Manually specify remote and branch to use every time
    • git push -u origin master
      • If a remote branch is not set up as an upstream, you can make it so
    • git pull
      • Downloads bookmark history and incorporates changes
    • git pull [remote] [branch]
      • Specify to pull a specific branch
    • git remote
      • See list of remote repos available
    • git remote -v
      • Detailed view of remote repos available
    • git remote add [remote] [url]
      • Add a new remote

32 Comentarios

Referencias (TrackBacks)

URL de trackback de esta historia


De: William Manley Fecha: 2015-12-04 18:15

If you like `git commit --amend` try `git commit --fixup=[sha]` followed by `git rebase -i --autosquash`. It allows you to change history of commits other than HEAD, but in a way where you're less likely to get confused if you manually fiddle with `git rebase` command list.

De: luisbg Fecha: 2015-12-04 18:44

That is a good trick Will!

De: Embedded Systems Fecha: 2015-12-05 20:19

Following the idea of luisbg a better way to change previous commits is to use the `git rebase -i Head~3` that will open for you the editor with all the options to rewrite, reorder, merge or delete your 3 previous commits. Just change the 3 by the number of commits you need to edit

De: Userman Fecha: 2015-12-06 02:22

What commit am I on?

git rev-parse HEAD

De: Matthew Russell Fecha: 2015-12-06 19:03

Good sheet. I use Oh-My-Zsh, so I always check my aliases for the shortcut. e.g. say I forget how to set my upstream, I do `alias | grep upstream` and get:

ggsup='git branch --set-upstream-to=origin/$(current_branch)'
glum='git pull upstream master'
gmum='git merge upstream/master'
gpu='git push upstream'

De: uali20 Fecha: 2017-09-17 07:22

This is really very nice post you shared, i like the post, thanks for sharing..

Cyber security training London

De: uali20 Fecha: 2017-09-17 07:27

Hi to everybody, here everyone is sharing such knowledge, so it’s fastidious to see this site, and I used to visit this blog daily
comptia a+ training

De: uali20 Fecha: 2017-09-17 07:32

Thanks for the informative and helpful post, obviously in your blog everything is good..
excel courses

De: uali20 Fecha: 2017-09-17 07:34

Personally I think overjoyed I discovered the blogs. java training

De: uali20 Fecha: 2017-09-17 07:35

I read that Post and got it fine and informative. Please share more like that. ccnp training

De: uali20 Fecha: 2017-09-17 07:53

So it should be, thanks for sharing this with us. comptia a+ course prices

De: uali20 Fecha: 2017-09-17 07:55

Thanks for such a great post and the review, I am totally impressed! Keep stuff like this coming.
mcse course

De: uali20 Fecha: 2017-09-17 07:56

I think this is an informative post and it is very useful and knowledgeable. cyber security training

De: uali20 Fecha: 2017-09-17 07:59

You've really made my day today with this. I hope you keep this up! sap courses

De: uali20 Fecha: 2017-09-17 08:03

I admire the valuable information you offer in your articles. Thanks for posting it. buat duit online

De: uali20 Fecha: 2017-09-17 08:05

Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post.
pakej percutian

De: uali20 Fecha: 2017-09-17 08:06

I can't wait to read lots of your posts.
perniagaan cenderahati

De: uali20 Fecha: 2017-09-17 08:08

I’ll probably keep it short and sweet and link to this instead if thats cool. Thanks. bercuti

De: uali20 Fecha: 2017-09-17 08:10

I love the way you write and share your niche! Very interesting and different! Keep it coming! belajar ebay

De: uali20 Fecha: 2017-09-17 08:12

I’ve been searching for some decent stuff on the subject and haven't had any luck up until this point, You just got a new biggest fan!. buat duit online

De: uali20 Fecha: 2017-09-17 08:14

Your content is nothing short of brilliant in many ways.melancong

De: uali20 Fecha: 2017-09-17 08:20

this blog was really great, never seen a great blog like this before. i think im gonna share this to my friends.. Birmingham Baby Gear Rental

De: uali20 Fecha: 2017-09-17 08:21

I’ll be sure to bookmark it and come back to read more of your useful info. Thanks for the post. I’ll definitely return.
gemstone jewellery

De: uali20 Fecha: 2017-09-17 08:23

Will be back again frequently to check up on new posts. Mercedes Benz Sprinter Van Rentals Atlanta

De: uali20 Fecha: 2017-09-17 08:25

This is a great post. I like this topic.This site has lots of advantage.I found many interesting things from this site. Meadow Park

De: uali20 Fecha: 2017-09-17 08:27

I quite like reading an article that can make people think. fertility clinic winter park

De: uali20 Fecha: 2017-09-17 08:30

I liked your article and I hope you will have many entries or more
ascension with earth

De: uali20 Fecha: 2017-09-17 08:32

I read a article under the same title some time ago, but this articles quality is much, much better. How you do this..
bcaa tablets

De: uali20 Fecha: 2017-09-17 13:01

Much thanks for composing such an intriguing article on this point. small business website design Brisbane

De: uali20 Fecha: 2017-09-21 12:05

Its a great pleasure reading your post.Its full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great work.
buy cheap fb comments

De: Consultant Caen Fecha: 2017-09-25 08:55

I have looked couple of days and discovered some spellbinding formed work on it. In any case, it is the best of all. Consultant Caen

De: Fecha: 2017-10-10 08:53

I read your blog frequently and I just thought I’d say keep up the amazing work!

Dirección IP: (c73e28d5dd)

©2007-2015 luis de bethencourt guimera
powered by Blogalia