# Git

## Tags

git tag -a v0.1 -m "tagname"  
git tag v0.1  
**Delete**  
git tag -d v0.1

## Branch

**Create branch**  
git branch stage  
**Check what branch you are in**  
git status  
git log --oneline --decorate  
git branch -a  
**Switch branches or restore working tree files.**  
git checkout stage  
**push changes**  
git add .  
git commit -m "blablabla"  
git push -u origin stage

## Merge

**Change branch to master**  
git checkout master  
**Merge**  
git merge stage  
**Delete local**  
git branch -d stage  
**Delete remote**  
git push --delete origin stage

## Merge conflicts

git status  
`FIND CONFLICT & FIX<br></br>`git add .  
git commit -m "blablabla"  
git merge stage

#### Create a branch based off of master

git checkout -b stage master

#### Edit files

git commit -a -m "Adds new feature"  
git checkout master  
git rebase stage

### Revert

git revert HEAD

#### or find a commit has with

git log --oneline --decorate  
git revert

### Git log

git log  
git log --graph  
git log --since="4 days ago"  
git log -S   
git log --stat  
git log --shortstat  
git log --pretty=format:"%h - %an - %ar - %s"

### See diff before commit

Git diff

### Remote

git remote show origin

### Cleaning

git gc --prune  
git gc --auto  
git config gc.pruneexpire "30 Days"

### Add new repo

<div id="bkmrk-git-config---global-"><fieldset>```
git config --global user.name "username"
git config --global user.email "email@email.com"
```

</fieldset><fieldset>Create a new repository ```
git clone <span class="clone">http://git.myhypervisor.ca/myhypervisor/project.git</span>
cd <span class="clone">project</span>
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
```

</fieldset><fieldset>Existing folder

```
cd existing_folder
git init
git remote add origin <span class="clone">http://git.myhypervisor.ca/myhypervisor/project.git</span>
git add .
git commit -m "Initial commit"
git push -u origin master
```

</fieldset><fieldset>Existing Git repository

```
cd existing_repo
git remote rename origin old-origin
git remote add origin <span class="clone"><a href="http://git.myhypervisor.ca/myhypervisor/project.git">http://git.myhypervisor.ca/myhypervisor/project.git</a></span>
git push -u origin --all
git push -u origin --tags 
```

</fieldset></div>