Vault7: CIA Hacking Tools Revealed
Navigation: » Latest version
Owner: User #524297
Git Tips & Tricks
Add your best Git tricks here!
Share the love! |
---|
The "I can never remember that alias I set" Trick
[alias]
aliases = !git config --get-regexp 'alias.*' | colrm 1 6 | sed 's/[ ]/ = /' | sort
Gitignore
$ git config --global core.excludesfile ${HOME}/.gitignore
Then create a ~/.gitignore. .gitignore follows glob syntax
The "The Git URLUniform Resource Locator is too long" Trick
('excerpt-include' missing)
The "I forgot something in my last commit" Trick
# first: stage the changes you want incorporated in the previous commit
# use -C to reuse the previous commit message in the HEAD
$ git commit --amend -C HEAD
# or use -m to make a new message
$ git commit --amend -m 'add some stuff and the other stuff i forgot before'
The "Oh crap I didn't mean to commit yet" Trick
# undo last commit and bring changes back into staging (i.e. reset to the commit one before HEAD)
$ git reset --soft HEAD^
The "That commit sucked! Start over!" Trick
# undo last commit and destroy those awful changes you made (i.e. reset to the commit one before HEAD)
$ git reset --hard HEAD^
The "Oh no I should have been working in a branch" Trick
# takes staged changes and 'stashes' them for later, and reverts to HEAD.
$ git stash
# creates new branch and switches to it, then takes the stashed changes and stages them in the new branch. fancy!
$ git stash branch new-branch-name
The "OK, what commit broke it!?" Trick
# Made lots of local commits and haven't run any tests...
$ [unittest runner of choice]
# Failures... now unclear where it was broken.
# git bisect to rescue.
$ git bisect start # to initiate a bisect
$ git bisect bad # to tell bisect that the current rev is the first spot you know was broken.
$ git bisect good <some tag or rev that you knew was working>
$ git bisect run [unittest runner of choice]
# Some runs.
# BLAMO -- git shows you the commit that broke
$ git bisect reset #to exit and put code back to state before git bisect start
# Fix code. Run tests. Commit working code. Make the world a better place.
The "Workaround Self-signed Certificates" Trick
This trick should no longer be necessary for using Stash, so long as you have the certificate for DEVLAN Domain Controller Certificate Authority installed.
# Issue: When attempting to clone (or any other command that interacts with the remote server) git by default validates
# the presented SSLSecure Socket Layer certificate by the server. Our server's certificate is not valid and therefore git exits out with an error.
# Resolution(Linux): For a one time fix, you can use the env command to create an environment variable of GIT_SSL_NO_VERIFY=TRUE.
$ env GIT_SSL_NO_VERIFY=TRUE git <command> <arguments>
# If you don't want to do this all the time, you can change your git configuration:
$ git config --global http.sslVerify false
$ git clone ssh://stash/proj/mcplugins.git
$ cd mcplugins
$ git checkout origin/master -b mylib
$ git filter-branch --prune-empty --subdirectory-filter plugins/mylib mylib
$ git push ssh://stash/proj/mylib.git mylib:master