Skip to main content

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
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

git config --global user.name "username"
git config --global user.email "email@email.com"
Create a new repository
git clone http://git.myhypervisor.ca/myhypervisor/project.git
cd project
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

Existing folder

cd existing_folder
git init
git remote add origin http://git.myhypervisor.ca/myhypervisor/project.git
git add .
git commit -m "Initial commit"
git push -u origin master

Existing Git repository

cd existing_repo
git remote rename origin old-origin
git remote add origin http://git.myhypervisor.ca/myhypervisor/project.git
git push -u origin --all
git push -u origin --tagsĀ