- Git Basics - Tips and Tricks
- Git tutorials
- Gitlab flow
- Learn Git Branching
- Dealing with pull requests day to day
- Modify a pre-existing repository protocol (HTTPS or SSH)
- Git Clean: Delete Already-Merged Branches
git branch --merged master | grep -v "\* master" | xargs -n 1 git branch -d
- Commit all changes excluding one file:
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`
- Git log with tree:
git log --graph --oneline
, alsogit log --pretty=format:"%h %s" --graph
- Only remove the tracking
git branch --unset-upstream
(thanks to karl-gustav for sharing) - Search a commit with a word inside its diff:
git log -GWORD
- Ammend after push
- Define shell alias in Git Bash for Windows
- Clone bibucket repository to GitHub
- Git stash
- Caching your GitHub password in Git
- Find a commit by message. Example:
git log --all --grep='Build 0051'
. - Package a node app (copy-pasted from npm/npm#1558):
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
- Restoring a deleted branch when it already exists in remote as a branch itself or merged in another existing branch. If your git repository is on github just go to
Code > branches
and use the "restore branch" feature.
git checkout -b <branch> <sha or the last commit of the branch to be restored>
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
.