-
-
Save mort3za/4d17114915e00d314ca6b7f7fe412eb1 to your computer and use it in GitHub Desktop.
# Add a ssh key to list of ssh keys of git | |
# first ensure that ~/.ssh/ folder is writable by current user. (if you are logged in as root can't solves this, change user by `su anotheruser` and then `chown anotheruser:anotheruser /home/anotheruser/.ssh/`) | |
# add a new key to .ssh/ folder of current user home. | |
ssh-keygen | |
# enter full address. `/home/anotheruser/.ssh/your_ssh_key_name` | |
# enter a passphrase | |
# if you used id_rsa as the name of key no need this step. | |
ssh-add `/home/anotheruser/.ssh/your_ssh_key_name | |
# enter passphrase | |
# done. | |
# now use this to clone a git repo | |
git clone git@github.com:...git |
# Add a remote url for existing git repo | |
git remote add origin git@gitlab.com:x/y.git | |
# change existing git remote to another address | |
git remote set-url origin git@gitlab.com:x/z.git |
Search in commits:
git log --all --grep='my search term'
It's better to learn native grep if you are on Linux.
git tag -l | xargs git tag -d
git fetch
- Delete all tags from the local repo. FWIW, xargs places each tag output by "tag -l" onto the command line for "tag -d". Without this, git won't delete anything because it doesn't read stdin (silly git).
- Fetch all active tags from the remote repo.
git log -p (or --patch) -2 (show log and changes in one command. only last 2 commits.)
git log --name-status --relative-date (same name-only with modified/added, 2 weeks ago)
git status -s | --short (only file changes)
git log --pretty=format:"%h - %an, %ar : %s"
ca82a6d - Scott Chacon, 6 years ago : changed the version number
(an=author name, who wrote changes directly. cn=commiter name, who applied commit to work)
git log -S 'function name to search in code'
git remote -v (show remote url)
git remote show origin (list remote branches, sync status of local to remote branches)
git ls-remote origin (list all remote refs including tags and hashes)
git branch -v (show last commit of every branch)
git branch -vv (show tracking branches + ahead/behind status => fetch to update)
git branch --no-merged master (show branches not merged to master)
git checkout --track origin/hotfix1 (shorthand for checkout -b hotfix1 origin/hotfix1)
git rebase --onto master feature1 feature1-patch (gets feature1-patch commits without commits of feature1, then rebases on master, in fact removes commits of feature1 from patch)
git diff master...feature (show diff of master and feature, but if master don't show commits of master which are not in feature) (another way of doing it: git diff $(git merge-base feature master
) )
Create zip archive of project
git archive master --prefix='project/' | gzip > `git describe master`.tar.gz
git archive master --prefix='project/' --format=zip > `git describe master`.zip
github manual:
https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/