# Basics

## Bare basics

#### semantic versioning
[https://semver.org/](https://semver.org/)

#### clone

* `git clone <url>` clone an arbitrary repository

#### add

* `git add .` add all files to stage

#### commit

* `git commit -m "some commit message"`  commit staged changes with inline commit message

#### ~~checkout~~ -> switch

* switch: [git-scm.com](https://git-scm.com/docs/git-switch)
  * `git switch -c <branch-name>` create new branch and switch to it

* checkout: 
  * ~~`git checkout <branch-name>` checkout the branch with given name~~
  * ~~`git checkout -b <branch-name>` create and checkout a new branch with given name~~


#### remotes

* `git push`
* `git fetch`
* `git pull`

#### log

`git log`

* `--graph` show visual graph in the terminal
* `--all` list all branches, not only current branch

alias in `~/.gitconfig`:
```config
[alias]
lg1 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)' --all
lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(auto)%d%C(reset)%n''          %C(white)%s%C(reset) %C(dim white)- %an%C(reset)'
lg = lg1
```

## config

### local
```bash
git config user.email "your_email@abc.example"
git config user.name "Example Name"
```

#### filemode
ignore filemod:
`git config (--global) core.fileMode false`

#### lineend

on linux: `git config --global core.autocrlf input`

on windows: `git config --global core.autocrlf true`

to keep `LF` as end of line in the repo. check [git docs](https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#_core_autocrlf)

#### store credentials

* in plaintext in `~/.git-credentials`
	* `git config --global credential.helper store`
    * add personal accesstoken to credetinal files: 
      ```
      git credential approve << EOF
      protocol=https
      host=gitlab.com
      username=private-token
      password=<<your personal access token>>
      EOF
      ```
    * content in files:
    ```
    # ~/.gitconfig
    [user]
        email = myMail@mymail.com
        name = Me
    [credential]
        helper = store
    
    # ~/.git-credentials
    https://private-token:............@gitlab.com
    ```
* in cache
	* `git config credential.helper 'cache --timeout=<timeout>'`
    * timeout in seconds (default 900 sec)
 

## others

[![](https://bookstack.draab.at/uploads/images/gallery/2022-10/scaled-1680-/image-1666903428458.png)](https://bookstack.draab.at/uploads/images/gallery/2022-10/image-1666903428458.png)


[![](https://bookstack.draab.at/uploads/images/gallery/2022-10/scaled-1680-/image-1666903459287.png)](https://bookstack.draab.at/uploads/images/gallery/2022-10/image-1666903459287.png)