Git Configuration
submodules
Fedora 26: install git-all
git submodule update --init
Other VC
Mercurial
Clone a project and push changes
$ hg clone https://www.mercurial-scm.org/repo/hello
$ cd hello
$ (edit files)
$ hg add (new files)
$ hg commit -m 'My changes'
$ hg push
Create a project and commit
$ hg init (project-directory)
$ cd (project-directory)
$ (add some files)
$ hg add
$ hg commit -m 'Initial commit'
To modify remote URLs, edit file .hg/hgrc
[paths]
default = ssh://hg@bitbucket.org/bowerth/michel-orgmode
default:pushurl = ssh://hg@bitbucket.org/bowerth/michel-orgmode
upstream = ssh://hg@bitbucket.org/edgimar/michel-orgmode
- Get help on setting paths
 $ hg help config.paths"
Commit message code
[=|+|!] [core|viewable|akka|docs|all]: <Actual message>.
=` means there are no API changes+means added funtionality!means breaking changes (source or binary)
Platforms
Github
- get user email address
 - https://api.github.com/users/
[username]/events/public 
Git workflow
%} +———+ +———–+ +————+ +———-+ +——–+ | | | | | | | | | | | Ignored | | Untracked | | Unmodified | | Modified | | Staged | | | | | | | | | | | | | ignore | | add | | edit | | add | | | <———-+-+ +-+——-> +-+——–> +-+——-> | | | | | | | | | | | | | | | | | | | | | | | | | rm | | | commit | | | | | | <——-+-+ <————————-+-+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +———+ +———–+ +————+ +———-+ +——–+ %}
GUI
http://sourceforge.net/projects/gitextensions/
Setup Git
- account
 - http://github.com/cis-itn-oecd/
alternative: bitbucket.com
git config --global http.proxy wsg-proxy.oecd.org:80
git config --global https.proxy wsg-proxy.oecd.org:80
git config --global http.sslverify false - attribution for commited content
 git config --global user.name "bowerth"
git config --global user.email "bo.werth@gmail.com"- add colors to git console
 git config --global color.ui auto- increase Git’s HTTP buffer
 git config --global http.postBuffer 2M- ssh key pair for authenticating
 ssh-keygen -t rsa -C "bo.werth@gmail.com"
-C: comment for reference
will be generated in~/
id_rsa: private part of the key (secret)
id_rsa.pub: public part of the key (share)- start 
ssh-agent $ eval "$(ssh-agent -s)"- add keypair to 
ssh-agent $ ssh-addfor keys in standard location/home/xps13/.ssh/id_rsa
enter passphrase- version of git
 git --version- create new repo
 git init [reponame]- create new file
 touch [filename]- status of repo
 git status- add to staging area
 git add [filename]- add untracked files, e.g. after renaming
 git add . -A- add and commit together (only for tracked files)
 git commit -a -m'[message]'- push repo to remote, e.g. github
 - create repo on github
git remote add origin git@github.com:bowerth/sdmxBrowser.git
git push -u origin master - undo push
 git reset cc4b63b
git stash
git push -f origin alpha-0.3.0
git stash pop- change remote URI
 git remote set-url origin https://github.com/bowerth/stanApi.git- nuke last commit and never see it again
 git reset --hard HEAD~1- set file back to untracked state
 git rm [filename]- ignore files permanently
 touch .gitignore
edit contents:
*.logignore file extension in root folder
**/*.logignore file extension in all subfolders
targetignore folder
*.*~ignore Emacs backup files
finally,git add .gitignore- view repo file tree
 tree
Cloning Repositories
- supported cloning protocols
 - 
    
- http: 
git clone http://server/user/project.gitno authentication - https: 
git clone https://user@server/user/project.gitcan be made to work with firewall - ssh: 
git clone git://server/user/project.gitrunning on port 9418 - file: 
git clone file:///myrepos/projectorgit clone /myrepos/project. Convenient way to manage different versions of large repo 
 - http: 
 - clone with different name
 git clone [repo] [alias name]
Command Composition, Storage, Log
- show recent commits
 git log- quit log view
 q- show last 3 commits
 git log HEAD^^^..HEAD- show last 3 commits with details (patch)
 git log HEAD^^^..HEAD -p- show specific previous commits with details (patch)
 git log HEAD~6..HEAD~4 -p- show recent commits in compressed view
 git log --pretty=oneline- show commits around specific hash
 git log [hash]- show two commits before specific hash
 git log [hash]^^..[hash]- show n commits before specific hash
 git log [hash]~[n]..[hash]- show details for last commit
 git show- rewrite the most recent commit message
 git commit --amend
Branching
- when to branch
 - 
    
- short lived
 - feature
 - release
 
 - list remote branches
 git branch -a- switch branches
 git checkout [branch]will automatically track remote branchorigin [branch]- fetch remote branch
 git fetch- remove branch after changing to other branch
 git branch -d [branch]- remove remote branch
 git push origin --delete [branch]- integrate pulled changes
 git rebase- update local remote-tracking branches
 git remote prune origin
Merging
- open files with merge conflict in sublime
 git diff --name-only | uniq | xargs sublime_text- accept own or foreign changes globally
 git merge --strategy-option theirs- file-based accept own or foreign changes
 git checkout --theirs path/to/the/conflicted_file- Source
 - McCullough and Berglund on Matering Git, O’Reilly
matthewmccullough
github-cheat-sheet 
Resetting
- Reset the staging area and the working directory to match the most recent commit
 git reset --hard
In addition to unstaging changes, the –hard flag tells Git to overwrite all changes in the working directory, too. Put another way: this obliterates all uncommitted changes, so make sure you really want to throw away your local developments before using it.
Submodules
- add submodule
 git submodule add https://github.com/bowerth/nsoApiBrowser.git inst/nsoApiBrowser
- to change submodule remote URL, modify 
.gitmodulesfile and rungit submodule sync 
Maintenance
BFG repo cleaner
- usage
 $ java -jar /home/xps13/Dropbox/Programming/Scala/bfg-1.12.6.jar --strip-blobs-bigger-than 100M ./.git
Other resources
- try.github.io: Got 15 minutes and want to learn Git?
 - GitHub Trainig Kit and page source
 - Pro Git book by S. Chacon and B. Straub
 - Become a git guru
 - Ry’s Git Tutorial
 - GitHub Pages Workflow
 - A Case of Computational Thinking: The Subtle Effect of Hidden Dependencies on the User Experience of Version Control
 - git-annex
 - buildamodule.com: git workflow training video
 - evrignaud.github.io: File Integrity Manager