## Initialize new user ##
git config --global user.name "forbobssake"
git config --global user.email "some@valid.mail"
git config --global core.editor vim
git config --global color.ui true
#git config --global merge.tool "meld"
git config --global alias.unstage 'reset HEAD --'
git config --global alias.lg 'log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit'
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.br branch
### Init new repo workflow
* mkdir repodir;
* cd repodir;
* git init;
* git add somefiles
* git commit -a -m "initial commit"
## Command Reference
git diff # changes not yet staged
git diff --stage # Changes staged
git diff --cached
git commit
git commit -m "commit message"
git commit -a # Add all tracked files to staging before committing
git commit -amend # uses staging area, if not changes, replace last commit message
git rm file # untrack and delete file
git rm --cached # remove files from staging area
git mv oldname newname # rename file
git log # default reverse order
git log -p # with diffs
git log --stat # lists modified files
git log -pretty
git log -<n> # n number of entries
-s [string] # search for string
git log --oneline --decorate # show HEAD pointer
git log --pretty=format:"%h - %an, %ar : %s" # timeline
git remote -v # show urls
git remote show origin # show urls
git remote add [shortname] [url]
git fetch # fetches data, no merging
git pull # pulls new data and merges
git tag -a V1.0 -m "my ver 1.0" # annotated tag
git push origin [tag] # explicitly push tag
git push --tags # explicitly push all tags
git branch # lists available branches
git branch -v # lists available branches with last commi
git branch -vv # lists tracking branches as well
git checkout [branch] # switch HEAD to branch
git checkout -b [branch] # create branch and switch HEAD to it
git branch -d [branch] # delete branch
git push origin --delete [branch] # delete remote branch
git merge [branch]
git status # shows merging conflicts
git mergetool # fires up the visual tool configured by merge.tool
git mergetool --tool-help # List supported merge tools
git mergetool --tool=<tool> # set them with
git checkout --track origin/serverfix # creates a local tracking branch of origin/serverfix
git checkout -b [name] origin/serverfix # same as above but with different local name
git clone -bare repo repo.git # creates a bare repository for server use
git ini --bare --shared # explicitly set group permission on repository
-----------
git config --global core.editor vim
git config --global color.ui true
List supported merge tools
git mergetool --tool-help
set them with
git mergetool --tool=<tool>
git status --short
git status -s
To see what you've changed but not yet staged, type git diff with no other arguments:
git diff
If you want to see what you've staged that will go into your next commit, you can use git diff --staged. This command compares your staged changes to your last commit:
git diff --staged
to see what you've staged so far:
git diff --cached
Skipping the Staging Area, Adding the -a option to the git commit command makes Git automatically stage every file that is already tracked before doing the commit, letting you skip the git add part:
git commit -a -m "<MESSAGE>"
Moving Files
git mv file_from file_to
Viewing the Commit History
git log
shows the difference introduced in each commit (limited to last two -2)
git log -p -2
if you want to see some abbreviated stats for each commit, you can use the --stat option:
git log --stat
In addition, the (short, full, and fuller) options show the output in roughly the same format but with less or more information, respectively:
git log --pretty=oneline
Timeline:
git log --pretty=format:"%h - %an, %ar : %s"
Undoing Things
You end up with a single commit the second commit replaces the results of the first.
git commit -m 'initial commit'
git add forgotten_file
git commit --amend
to unstage files do:
git reset HEAD <file>
To get around writing multiple commands to ignore all of these files and un-track them, I did this
git rm -r --cached .
git add -A
git commit -am 'Removing ignored files'
Basic Branching and Merging
create and checkout(switch) to <newbranch>
git checkout -b <newbranch>
[user]
email = vociferous@smex.dk
name = Daniel Moelbaek
[core]
editor = vim
excludesfile = /home/berry/.config/git/ignore
[push]
default = nothing
[alias]
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
co = checkout
ci = commit
st = status
br = branch
git clone --recurse-submodules http://address
#git
alias ga="git add"
alias gb="git branch"
alias gc="git commit -m"
alias gst="git status"
alias gd="git diff"
alias gf="git fetch"
alias gfp="git fetch --prune"
alias gm="git merge"
alias grb="git rebase"
alias gp="git push"
alias gl="git pull"
alias gu="git unstage"
alias gg="git graph"
alias ggg="git graphgpg"
alias gco="git checkout"
alias gcb="git checkout -b"
alias gcs="git commit -S -m"
### Init new repo
* mkdir repodir;
* cd repodir;
* git init;
* git add somefiles
* git commit -a -m "initial commit"
*
Undoing Things
You end up with a single commit the second commit replaces the results of the first.
git commit -m 'initial commit'
git add forgotten_file
git commit --amend
to unstage files do:
git reset HEAD <file>
To get around writing multiple commands to ignore all of these files and un-track them, I did this
git rm -r --cached .
git add -A
git commit -am 'Removing ignored files'
git remote add origin vociferous@smex:/srv/git/
git clone --bare /path/repo /where/to/store.git/
scp -r store.git smex:/srv/git/
git clone --recurse-submodules http://address
Last modified: Tue May 14 08:52:47 2024