Skip to content

Instantly share code, notes, and snippets.

@carloscasalar
Last active October 11, 2018 13:33
Show Gist options
  • Save carloscasalar/cc7a0e3ecb0ecccecc56 to your computer and use it in GitHub Desktop.
Save carloscasalar/cc7a0e3ecb0ecccecc56 to your computer and use it in GitHub Desktop.
Git tips

Git tips

git update-index --assume-unchanged path/to/file.txt
git commit -a -m "MOBILE-1234: changed a bunch of files but excluded that one I'm saving for later."
git update-index --no-assume-unchanged path/to/file.txt`
npm install blah
git commit . -m "Update blah to version watever"
# dev some more...

# some time later...
# make a release
git tag -s v1.2.3
git archive --format=tar --prefix=my-app-v1.2.3/ v1.2.3 | gzip > my-app-v1.2.3.tar.gz
scp my-app-v1.2.3.tar.gz production-box.com:
ssh production-box.com "./deploy.sh my-app-v1.2.3.tar.gz" #or however you do it
  • Remove local branches that no longer exist in remote
git fetch -p && for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'`; do git branch -D $branch; done
git checkout branch-B
git log  # Note the SHA of most recent commit (M)
git rebase --onto M <commit before X> Y
git rebase HEAD branch-B
git checkout -b <branch> <sha or the last commit of the branch to be restored>

Tooling

Don’t type your password every time

Copy-pasted from git-branching-remote:

If you’re using an HTTPS URL to push over, the Git server will ask you for your username and password for authentication. By default it will prompt you on the terminal for this information so the server can tell if you’re allowed to push.

If you don’t want to type it every single time you push, you can set up a “credential cache”. The simplest is just to keep it in memory for a few mintues, which you can easily set up by running git config --global credential.helper cache.

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