forked from andonome/lk
change formatting
input examples are now given as ```bash input $ARG1 ``` While outputs use md's '> ' sign as a quote.
This commit is contained in:
146
data/git.md
146
data/git.md
@@ -6,93 +6,140 @@ tags: [ "Documentation", "data" ]
|
||||
|
||||
## New Machines
|
||||
|
||||
> git config --global user.email *"malinfreeborn@posteo.net"*
|
||||
```bash
|
||||
git config --global user.email "$YOUR_EMAIL"
|
||||
```
|
||||
|
||||
> git config --global user.name *"Malin Freeborn"*
|
||||
```bash
|
||||
git config --global user.name "$YOUR_NAME"
|
||||
```
|
||||
|
||||
# New Git
|
||||
|
||||
Start a git in a folder:
|
||||
Start a git in directory `$DIR`:
|
||||
|
||||
> mkdir *project* && cd *project*
|
||||
```bash
|
||||
mkdir $DIR && cd $DIR
|
||||
```
|
||||
|
||||
> git init
|
||||
```bash
|
||||
git init
|
||||
```
|
||||
|
||||
Make a file explaining what the project does:
|
||||
|
||||
> vim README.md
|
||||
```bash
|
||||
vim README.md
|
||||
```
|
||||
|
||||
> git add README.md
|
||||
Add this to the git:
|
||||
|
||||
```bash
|
||||
git add README.md
|
||||
```
|
||||
|
||||
Then make the initial commit, explaining the change you just made:
|
||||
|
||||
> git commit
|
||||
```bash
|
||||
git commit
|
||||
```
|
||||
|
||||
# Working
|
||||
|
||||
Once you make a change to some file ("file.sh"), add it and make a commit explaining it.
|
||||
Once you make a change to some file, add it and make a commit explaining it.
|
||||
|
||||
> git add file.sh
|
||||
```bash
|
||||
git add $FILE
|
||||
```
|
||||
|
||||
> git commit -m"change file.sh"
|
||||
```bash
|
||||
git commit -m"change $FILE"
|
||||
```
|
||||
|
||||
Check your history:
|
||||
|
||||
> git log
|
||||
```bash
|
||||
git log
|
||||
```
|
||||
|
||||
# Remotes
|
||||
|
||||
If you want to keep a copy on a public site such as Gitlab, so others can see it, then go there and create a blank project (no readme, nothing).
|
||||
Find the address you want and add it as a remote:
|
||||
Give it the same name as the `$DIR` directory, above.
|
||||
|
||||
> git remote add *gitlab* *https://gitlab.com/username/projectx*
|
||||
Add this as a remote:
|
||||
|
||||
```bash
|
||||
REMOTE=gitlab
|
||||
git remote add $REMOTE https://gitlab.com/$USERNAME/$DIR
|
||||
```
|
||||
|
||||
Tell git you're pushing the branch "master" to the remote repo "origin":
|
||||
|
||||
> git push -u master origin
|
||||
```bash
|
||||
git push -u master origin
|
||||
```
|
||||
|
||||
If someone makes a change on the remote, pull it down with:
|
||||
|
||||
> git pull
|
||||
```bash
|
||||
git pull
|
||||
```
|
||||
|
||||
# Branches
|
||||
|
||||
A branch is a full copy of the project to test additional ideas.
|
||||
You can make a new branch called 'featurez' like this:
|
||||
|
||||
> git branch *featurez*
|
||||
```bash
|
||||
git branch *featurez*
|
||||
```
|
||||
|
||||
Have a look at all your branches:
|
||||
|
||||
> git branch
|
||||
```bash
|
||||
git branch
|
||||
```
|
||||
|
||||
Switch to your new branch:
|
||||
|
||||
> git checkout *featurez*
|
||||
```bash
|
||||
git checkout *featurez*
|
||||
```
|
||||
|
||||
And if your changes are rubbish, checkout the "master" branch again, then delete "featurez":
|
||||
|
||||
> git branch -D *featurez*
|
||||
```bash
|
||||
git branch -D *featurez*
|
||||
```
|
||||
|
||||
Or if it's a good branch, push it to the remote:
|
||||
|
||||
> git push *origin* *featurez*
|
||||
```bash
|
||||
git push *origin* *featurez*
|
||||
```
|
||||
|
||||
## Merging
|
||||
|
||||
Once you like the feature, merge it into the main branch. Switch to master then merge it:
|
||||
|
||||
> git merge *featurez*
|
||||
```bash
|
||||
git merge *featurez*
|
||||
```
|
||||
|
||||
and delete `featurez` as you've already merged it:
|
||||
|
||||
> git branch -d featurez
|
||||
```bash
|
||||
git branch -d featurez
|
||||
```
|
||||
|
||||
# Subtree
|
||||
|
||||
## Pulling another git repo into a subtree
|
||||
|
||||
> git subtree add -P config git@gitlab.com:bindrpg/config.git master
|
||||
```bash
|
||||
git subtree add -P config git@gitlab.com:bindrpg/config.git master
|
||||
```
|
||||
|
||||
## Pulling a Subtree from an existing git
|
||||
|
||||
@@ -100,13 +147,17 @@ The project has subdirectories sub-1,sub-2,sub-3. The first should be its own r
|
||||
|
||||
First, we extract its history as an independent item, and make that into a seprate branch.
|
||||
|
||||
> git subtree split --prefix=sub-1 -b sub
|
||||
```bash
|
||||
git subtree split --prefix=sub-1 -b sub
|
||||
```
|
||||
|
||||
If you want something a few directories deep, you can use `--prefix=sub-1/dir-2/dir-3
|
||||
|
||||
Then go and create a new git somewhere else:
|
||||
|
||||
> cd ..;mkdir sub-1;cd sub-1;git init --bare
|
||||
```bash
|
||||
cd ..;mkdir sub-1;cd sub-1;git init --bare
|
||||
```
|
||||
|
||||
Then go back to your initial git repo, and do the following:
|
||||
|
||||
@@ -114,38 +165,57 @@ git push ../subtest sub:master
|
||||
|
||||
Finally, you can clone this repo from your original.
|
||||
|
||||
> git clone ../subtest
|
||||
```bash
|
||||
git clone ../subtest
|
||||
```
|
||||
|
||||
# Tricks
|
||||
|
||||
## Delete All History
|
||||
|
||||
> git checkout --orphan temp
|
||||
```bash
|
||||
git checkout --orphan temp
|
||||
```
|
||||
|
||||
> git add -A
|
||||
```bash
|
||||
git add -A
|
||||
```
|
||||
|
||||
> git commit -am "release the commits!"
|
||||
```bash
|
||||
git commit -am "release the commits!"
|
||||
```
|
||||
|
||||
> git branch -D master
|
||||
```bash
|
||||
git branch -D master
|
||||
```
|
||||
|
||||
> git branch -m master
|
||||
```bash
|
||||
git branch -m master
|
||||
```
|
||||
|
||||
> git push -f origin master
|
||||
```bash
|
||||
git push -f origin master
|
||||
```
|
||||
|
||||
Gitlab requires more changes, such as going to `settings > repository` and switching the main branch, then stripping protection.
|
||||
|
||||
## Clean up Bloated Repo
|
||||
|
||||
> git fsck --full
|
||||
```bash
|
||||
git fsck --full
|
||||
```
|
||||
|
||||
> git gc --prune=now --aggressive
|
||||
```bash
|
||||
git gc --prune=now --aggressive
|
||||
```
|
||||
|
||||
> git repack
|
||||
```bash
|
||||
git repack
|
||||
```
|
||||
|
||||
## Find Binary Blobs
|
||||
|
||||
```
|
||||
|
||||
```bash
|
||||
git rev-list --objects --all \
|
||||
| git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' \
|
||||
| sed -n 's/^blob //p' \
|
||||
|
Reference in New Issue
Block a user