Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
clone is used in git to copy a project into your machine as a git project and do you works on it. Sometime a project (specially front projects) are so heavy and has lots of history which makes cloning to takes an hour or more (depending on the depth and the size of the repo).

The solution is --depth, with --depth you can specify how shallow a clone could be and how much commit of the past should be brought into your system. So for example you can clone like this:
git clone myhost:frontier/web.git --depth=1
It will copy the whole project BUT it just copies the last commit on the tip of the current branch in your server (most likely master) which is the default behaviour of git that set --single-branch. So if you checkout to dev you wont see your last changes
in dev branch. In case you want to shallow copy the whole project and retrieve the lat commit on the tip of all remote branches just use --no-single-branch.

So finally we can:
git clone myhost:frontier/web.git --depth=1 --no-single-branch

Now if you change your branch (checkout) to dev, you will see that recent changes of the dev branch on the remote repo server is present in your system.

to see the last commit ids that you have in your system, open YOUR_PROJECT/.git/shallow file and see the content of the file. Mine is as below:
8252b87c82b4be7b7b4edaa12f2168ff165fc7af #refers to my master last commit id
d50bdeeecc595e86818c68d734613542206bf972 #refers to my dev last commit id

#git #branch #no-single-branch #single-branch #depth #clone
Did you push a very large file into git? Does everyone yell at you about your commit and your uselessness? Are you a junky punky like me that just ruin things? Oh I'm kidding...

Because of that big file cloning the repo again would take a long long time. Removing the file locally and pushing again would not solve the problem as that big file is in Git's history.

If you want to remove the large file from your git history, so that when everyone clone the repo should not wait for that large file, just do as follow:

git filter-branch --tree-filter 'rm path/to/your/bigfile' HEAD

git push origin master --force

I should note that you should be in the root of git repo.

If you need to do this, be sure to keep a copy of your repo around in case something goes wrong.

#git #clone #rm #remove #large_file #blob #rebase #filter_branch
How to clone a database in MySQL?

mysqldump -u root db_name | mysql -u root new_db_name

NOTE: if it gets password provide -p to both commands.

#mysql #clone #copy #database #copy_database