Skip to content

Instantly share code, notes, and snippets.

@jorwan
Forked from frangeris/commands.md
Last active August 29, 2015 14:19
Show Gist options
  • Save jorwan/602e07d2bcd7828f5659 to your computer and use it in GitHub Desktop.
Save jorwan/602e07d2bcd7828f5659 to your computer and use it in GitHub Desktop.

Common git commands

This is a list of useful commands for git for fast search and ops developers, enjoy and comments for suggest all welcomes :D


Public repo .tar for download versions: https://www.kernel.org/pub/software/scm/git/

Delete with git all files listed as deleted:

$ git rm $(git ls-files --deleted)

Delete a branch DOWN in the local repository:

$ git branch [branch name] --delete

Delete a branch UP in the services repository:

$ git push origin --delete [branch name]

Do not track changes on specific file:

$ git update-index --assume-unchanged [file]

Track changes again:

$ git update-index --no-assume-unchanged

List hidden tracked files:

$ git ls-files -v | grep '^[[:lower:]]'

Cleaning up cache when git ignore fail (options):

$ git rm -r --cached . 
$ git add . 
$ git commit -m "Fixed untracked files"

Clone a repo specifying the branch:

$ git clone -b <branch> <myproject>.git

Ignore mode file change, setting up git:

$ git config core.fileMode false

git checkout, doesn't work... possibilities:

$ git config --global core.autocrlf false
$ vim .gitattributes # comment line "* text=auto"

Setting up git color:

$ git config --global color.ui true

Rolling back a commit:

$ git reset --soft 'HEAD^'

Discard last commit:

$ git reset HEAD --hard
$ git reset --hard origin/master

Merging conflicts (accept theirs):

$ git checkout --theirs

Merging conflicts (accept ours):

$ git checkout --ours

Remove a remote:

$ git remote rm <remote>

Resolve problem with CRLF sequence:

$ git diff --ignore-space-at-eol

Add just tracked files to the stage:

$ git add -u .

Revert changes on a specifuc file commited and begin again:

$ git checkout commit-reff~1 -- <file name>

Remove the last commit and set the change to "Changed but not updated":

$ git reset HEAD~1

Export a "clean" project:

$ git archive master | tar -x -C </somewhere/else>
$ git archive master | bzip2 > <source.tar.bz2>
$ git archive --format zip --output <zipfile.zip> master

Note: This is a synonym to svn export. What this does is export and compress a repository without any .git* files.

Removing file from all history: https://help.github.com/articles/remove-sensitive-data/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment