Skip to content

Instantly share code, notes, and snippets.

@ahaubold
Last active August 28, 2019 08:56
Show Gist options
  • Save ahaubold/2bed3113be49fbfd5dbf to your computer and use it in GitHub Desktop.
Save ahaubold/2bed3113be49fbfd5dbf to your computer and use it in GitHub Desktop.
GIT Basics
# show log since last version
git log `git describe --tags --abbrev=0`..HEAD --oneline
# show log since a defined version
git log 3.15.0..HEAD --decorate=short --oneline
###########
### GIT ###
###########
# @see https://rogerdudler.github.io/git-guide/index.de.html (german)
################
# often needed #
################
# branch: short information
git branch -vv
# branch: detailed information
git remote show origin
# show branches
git branch -r
# List repos
git remote -v
# shows list like occures after svn checkout
git diff --name-status master
#########################
# working with a branch #
#########################
# create new branch
git checkout -b branch_name
# develop and change
git commit -a
# push to remote repository
git push origin branch_name
# reintegrate branch into trunk
# first: switch back to master
git checkout master
# second: get the changes into master branch
git merge branch_name
# third: push merged changes to remote repo
git push
# on test machine
git pull
git checkout branch_name
# checkout tag: see below
###########
# Tagging #
###########
# add tag
git tag -a 2.5.4
git push --tags
# delete tag (shouldn't be used often)
git tag -d 2.5.3
# push tag changes to remote
git push --tags
# switch to tag on live system / checkout tag
git fetch --tags
git checkout tags/3.0.0
##########
# Remove #
##########
# Remove a branch
git branch -d the_local_branch
git push origin :the_remote_branch
# or simply use the new syntax (v1.7.0)
git push origin --delete the_remote_branch
############
# Checkout #
############
cd my_project
git init
# shorthand for fetch and merge
git pull
# set upstream branch
git branch --set-upstream-to=origin/master master
# checkout a project or branch in current directory
git clone info@domain.de:my_project.git .
git clone git@github.com:gitusername/project.git --branch branchname .
git push --set-upstream origin branchname
git remote add origin https://github.com/username/projectname.git
git push -u origin master
##########
# Commit #
##########
# TYPO3 guidlines for commit messages
# @see http://docs.typo3.org/flow/TYPO3FlowDocumentation/stable/TheDefinitiveGuide/PartV/CodingGuideLines/PHP.html#commit-messages
git commit -m "My initial commit message"
# or
git commit -a
# add a file for commit
git add filename.txt
# undo git add
git reset filename.txt
git add *
# add all files shown by git status
git add -u
# revert a local change of a file
git checkout HEAD -- verloren.txt
# or
git checkout c5f567 -- file1/to/restore file2/to/restore
# stash specific files
git stash -p
# delete a branch local and remote
git push origin --delete <branchName>
# show the repos
git remote -v
# show the change log / last commits
git log --oneline --decorate --graph --all
# show changes before pull (files only)
git diff --stat
# edit the config
nano .git/config
# get current commit with shortened hash, with long hash it's %H
git log --pretty=format:'%h' -n 1
###########
# SSH key #
###########
# generate SSH keys
# https://help.github.com/articles/generating-ssh-keys/
ssh-keygen -t rsa -b 4096 -C "info@mygithubmail.de"
# get the key as terminal output
cat ~/.ssh/id_rsa.pub
# or alternitavely
xclip -sel clip < ~/.ssh/id_rsa.pub
# test github connection
ssh -T git@github.com
# Configuring Git over SSH to login once
# @see https://stackoverflow.com/questions/1595848/configuring-git-over-ssh-to-login-once
# check what protocol you're using - https?
git config -l
# look at the line starting with 'remote.origin.url'. To switch your protocol
git config remote.origin.url git@github.com:your_username/your_project.git
## start ssh agent
eval $(ssh-agent)
# add private key to agent
ssh-add
# master branch nach branch app_1_7 kopieren
# clone master, create branch and switch to it, push it to remote origin
git clone https://github.com/your_username/your_project.git .
git branch app_1_7
git checkout app_1_7
git push origin app_1_7
# anschließend master entfernen und app_r3 zum master machen
# vorher: default branch in github weboberfläche ändern
git push origin :master
# delete old master branch in app_r3 WC
git branch -d master
# create and switch to new master, push it to remote
git branch master
git checkout master
git push origin master
# tag 3.0.0 für master erstellen und als release kennzeichnen
git tag -a 3.0.0
# live1 auf tag 3.0.0 umstellen
git checkout tags/3.0.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment