create git:// protocol

$ sudo apt-get install xinetd
$ sudo nano /etc/xinetd.d/git

# where highlighted if incorrect the service may not start

service git
{
        disable = no
        type            = UNLISTED
        port            = 9418
        socket_type     = stream
        wait            = no
        user            = nobody
        server          = /usr/bin/git
        server_args     = daemon --inetd --export-all --base-path=/var/fsq
        log_on_failure  += USERID
}

$ sudo /etc/init.d/xinetd restart
$ sudo /etc/init.d/xinetd status

# view the number of active services

active_services = 2
available_services = 2
descriptors_free = 1014
running_servers = 0
Logging service = enabled

# Now, all git repositories beneath /var/fsq will be available to anyone who asks.
# git clone git://[hostname]/my-repo.git
$ git clone git://baligena.com/my-repo.git

# sources
http://stackoverflow.com/questions/2538015/why-wont-git-daemon-serve-my-repository#answer-2539138

Installing Gitlab

Raspberry Pi

# login as root
$ sudo su

# follow gitlab installation for specified operating system
$ apt-get install gitlab-ce

# install web server
$ apt-get install nginx

# check log for errors. Port conflicts will be notified
$ cat /var/log/nginx/error.log

# change port if desired
$ nano /etc/nginx/sites-enabled/default

server {
        listen 81 default_server;
        listen [::]:81 default_server;

        # SSL configuration

# reconfigure gitlab
$ gitlab-ctl reconfigure

# change gitlab port to match nginx port
$ nano /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml

  ## GitLab settings
  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: gitlab.example.com
    port: 81
    https: false

.......

test:
  <<: *base
  gravatar:
    enabled: true
  gitlab:
    host: localhost
    port: 81

# change gitlab port to match nginx port
$ nano /etc/gitlab/gitlab.rb

## Url on which GitLab will be reachable.
## For more details on configuring external_url see:
## https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/configuration.md#configuring-the-external-url-for-gitlab
external_url 'http://gitlab.com.local:81/'

........

## Advanced settings
# unicorn['listen'] = '127.0.0.1'
# unicorn['port'] = 8081
# unicorn['socket'] = '/var/opt/gitlab/gitlab-rails/sockets/gitlab.socket'
# unicorn['pidfile'] = '/opt/gitlab/var/unicorn/unicorn.pid'

# reconfigure gitlab
$ gitlab-ctl reconfigure

# restart gitlab
$ sudo gitlab-ctl restart

# restart server
$ sudo reboot

# restart nginx
$ /etc/init.d/nginx restart

# check if listen to port
$ nmap -sS 192.168.0.14

PORT     STATE SERVICE
81/tcp   open  hosts2-ns
85/tcp   open  mit-ml-dev
443/tcp  open  https
3128/tcp open  squid-http
3389/tcp open  ms-wbt-server
9418/tcp open  git

# navigate to page. Be careful with browser cache (especially firefox)
http://192.168.0.14:81/

sources

http://www.thecfguy.com/blog/how-to-change-default-port-for-gitlab/

troubleshooting

# Reconfigure freezes at ruby_block[supervise_redis_sleep] action run
https://gitlab.com/gitlab-org/omnibus-gitlab/issues/430#note_1308607
http://stackoverflow.com/questions/22328923/impossible-to-install-gitlab-on-ubuntu-12-04#answer-25785708

when accessing the file tab there was an ajax request that was loading a 500 error page.
Looked into the log by running
$ sudo gitlab-ctl tail
and found this error message

Errno::ENOMEM (Cannot allocate memory - /opt/gitlab/embedded/bin/git):
.......

Found out that not enough memory was being allocate. May be because its a raspberry pi and it has limited memory.
The solution was to reduce unicorn worker processes thus reducing the memory consumption.
$ nano /etc/gitlab/gitlab.rb

##################
# GitLab Unicorn #
##################
## Tweak unicorn settings.

# unicorn['worker_timeout'] = 60
unicorn['worker_processes'] = 1

# Deleting branches and committing changes (edit file) using GitLab hangs it
error: proxyRoundTripper: POST " failed with: "EOF"

The corresponding unicorn worker waits for the git hook to complete and can not serve other requests during this time. The hook uses the GitLab web API to check if the user is allowed to execute the requested git operation. Because I had unicorn running with only one worker, no other worker was available to serve the API request, thus resulting in a deadlock.
https://gitlab.com/gitlab-org/gitlab-ce/issues/13947

$ nano /etc/gitlab/gitlab.rb

unicorn['worker_processes'] = 2

# remove GitLab
$ apt-get purge gitlab-ce

# remove nginx
$ apt-get purge nginx nginx-common nginx-full

Use apache server instead of nginx

followed these these steps

# Additional
Before running 'gitlab-ctl reconfigure', first run 'gitlab-ctl start postgresql', else there will be an error that postgresql is not running.

# enable apache modules
# http://stackoverflow.com/questions/25785903/gitlab-7-2-1-with-apache-server-instead-of-nginx#comment-65475363
# http://askubuntu.com/questions/64454/how-do-i-enable-the-mod-rewrite-apache-module-for-ubuntu-11-04#answer-64460
$ sudo a2enmod rewrite
$ sudo a2enmod proxy_http

If you get permission errors like "You don't have permission to access /assets/logo-white-0b53cd4ea06811d79b3acd486384e047.png on this server." then you need "Require all granted" in the <Location> in your apache vhost configuration file

# sources
http://stackoverflow.com/questions/25785903/gitlab-7-2-1-with-apache-server-instead-of-nginx#answer-25809733

Raspberry Pi troubleshooting

Error: ‘No space left on device’
# check memory size.

$ df -h

# None should have 100% but if so here is how to fix it

$ sudo raspi-config

# select ‘Expand Filesystem’ then restart computer when prompted
https://steve0hh.wordpress.com/2013/02/10/raspberry-pis-no-space-left-on-device-error-message/

Changing keyboard layout

$ sudo raspi-config

# select Internatinalisation Options->Change Keyboard Layout->Generic 105-key (Intl) PC->Other->English (US)->English (US)->Right Alt (AltGr)->No compose key->…
# alternative http://baligena.com/changing-keyboard-layout/

Fix Raspberry pi zero wifi disconnect/sleeps after a certain period of time. source, and here

$ sudo nano /etc/modprobe.d/8192cu.conf

Add these lines
# Disable power management
options 8192cu rtw_power_mgnt=0 rtw_enusbss=0

After a while the monitor will wont work and you will not be able to see the command line once you plug in the HDMI. It goes black and you cannot see the screen. In order to keep the terminal alive here what is need to be done. source, source2

$ sudo nano /etc/rc.local

ABOVE the “exit 0” line insert:
setterm -blank 0 -powerdown 0 -powersave off

$ sudo reboot

# As of 2016-07-03 you cannot update raspberry pi packages thus some programs cannot be updated such as git.
# to have the latest git version you will need to install it by source
How To Install Git from Source

Git on Windows passwordless with plink

Manual way:

Use Git on Windows with a private key by using pagent, putty and plink

Or the automatic way:

When installing “git on windows” on the “Choosing the SSH executable” screen choose “Use (Tortoise)Plink” and browse for plink.exe.

stackoverflow answer

If you see the below message and it freezes the way to fix it is to open putty, type in the host name (like bitbucket.org), click open, click yes in the popup to cache the host key then close putty

The server's host key is not cached in the registry. You
have no guarantee that the server is the computer you
think it is.
The server's rsa2 key fingerprint is:
ssh-rsa 2048 24:5e:d9:30:a7:96:92:f5:f1:f1:ff
If you trust this host, enter "y" to add the key to
PuTTY's cache and carry on connecting.
If you want to carry on connecting just once, without
adding the key to the cache, enter "n".
If you do not trust this host, press Return to abandon the
connection.
Store key in cache? (y/n) y

Notes:
pageant needs to be running and loged in with private key
windows

tags:
git windows ssh private key

Git Commands

http://www.ndpsoftware.com/git-cheatsheet.html#loc=index;

GitHub error(can’t push to github public key) – http://help.github.com/linux-set-up-git/

$ git reset --hard 1e45d (Deletes the commit after you selected or moves the branch pointer to where you decide to go)

# equivalent to svn revert, If you want to throw out all of the changes you’ve been working on
$ git reset --hard

# reset/undo a single file, revert
$ git checkout -- [filename]

#go back one commit
$ git reset [branch]~1

#undo the commit
# without auto commit
$ git revert -n 1sdf34
# with auto commit
$ git revert 1sdf34

$ git branch -d [path] # delete branch
$ git push origin --delete [branch_name] # delete remote branch
$ git push origin master-testing:master-testing # push to a branch that is not currently checked out
$ git branch -a #show all branch local and remote
$ git branch -rd public/master # removes remote branch
$ git branch [branch name] (creates branch but doesn't check it out)
$ git checkout -b [branch name] (shortcut: creates branch and checks it out)
$ git checkout -b new_database upstream/new_database (creates branch, checks it out and track from upstream)
$ git branch -u [remote] [branch name] (set current branch upstream)

# this will go to that commit but you will be in a no name branch
$ git checkout fa15gvwsgc

# get a specific file from another branch into current branch
git checkout [branch] [file_path]

# clone and checkout only a file
# http://stackoverflow.com/questions/2466735/how-to-checkout-only-one-file-from-git-repository#answer-2466755

# to remove the red delete: not the whole directory system, stage the deleted files
$ git add -u

# add parts of the file, chucks
$ git add -p

#to remove from stage or untrack a file
$ git rm --cached -f <file name>

$ git branch (check branches and which one your in)
$ git diff branch1 branch2 (show what line of code has been changed or git difftool)

# Show git diff on file in staging area, view code that is going to be committed
$ git diff --staged

# difference between file in 2 different branches
git difftool [branch1] [branch2] — [file]
git diff [branch1] [branch2] — [file]

# Showing which files are different in 2 branchesf
git diff –name-status [branch1] [branch2]

$ git commit -am [commit description] (shortcut: this allows you to add (-a) and name the commit (-m) all at once)

$ git config --global color.ui true (set git to be colorful)

$ git clone git://github.com/schacon/ticgit.git #read Only - (this downloads a folder(directory) from github on to your computer. to work with it you need to change the directory(cd))
$ git clone username@192.168.1.114:/custom_path
$ git clone server:/path [custom folder name]
$ git clone -o [custom name] user@baligena.com:/custom_path

# git inside another git
# view all submodules
$ git submodule
# http://git-scm.com/book/en/v2/Git-Tools-Submodules
$ git submodule add https://github.com/baligena/firstRepo.git [name/path]
# update to newest remote commit, will unbranch
$ git submodule update --remote [repository]
or
$ git submodule update --init
# easy way pull latest of all submodules
$ git submodule foreach git pull origin master

# remove submodule
$ git submodule deinit [submodule name]
$ git rm [submodule name]

pull == fetch + merge #stick with fetch and merge, pull may throw error if you dont know what you doing. Like trying to pull anything other than the master branch

$ git log --online --graph --all --decorate # a nice/pretty way to see the git log
$ git log --pretty=format:"%an %h" (formats the log output to your liking)

# reachable different between two branches
# what commits hasn’t been merged into master
# what commits is in branchA that is not merged into master yet? is there anything unique
$ git log branchA ^master

# shows how many lines were change by the plus and minus symbol
$ git log --stat

# shows what was changed (diff) in each file/commit ( 2 first commits )
$ git log -p -2

# show log tree of only local branches
$ git log --branches --not --remotes

# show log tree of only remote branches
$ git log --branches --remotes

# show log of branches by regular expression
$ git log --branches=version1*

# show log of branches by regular expression
$ git log --branches=version1*

# Look for differences whose patch text contains added/removed lines that match, regular expression (regex)
$ git log -G fsq*

# commits per user
$ git shortlog -sne

# show git settings
$ git config --list

#set alias
$ git config --global alias.lol "log --oneline --graph --decorate"

#set alias with date, https://coderwall.com/p/euwpig
$ git config --global alias.lol "log --graph --pretty=format:'%Cred%h%Creset %Cgreen%cr%C(yellow)%d%Creset %s %C(bold blue)<%an>%Creset'"

$ git stash save "name" #saves the current state without having to commit see http://book.git-scm.com/4_stashing.html
$ git stash list #shows your stashes
$ git stash apply stash@{1} #apply you save stash

# video on how to set up your own git server like github – http://www.youtube.com/watch?v=DDzeiI2yZL8&feature=related

#when pushing to the server make sure your not in the branch your pushing to
# its located in the .git/config line 10
# make sure you have permission to .git folder (sudo chgrp)
$ git remote add origin username@xxx.xxx.x.xxx:/directoryName
#removes origin, so you can change it. file location is => /.git/config
$ git remote rm origin

# rename a remote
$ git remote rename <old> <new>

#creates an alias
$ git push origin [branch Name] or $ git push origin --all
$ git fetch origin [branch Name]

# I tried to tie htdocs in lampp a server and was getting an error when I push because I had to change the owners from root to username. I ran
$ chown username -R htdocs

#git mergetool set which one you want to use/candidates
$ git mergetool -t <candiatename>

# instrustions on how to use kdiff3 – http://kdiff3.sourceforge.net/doc/merging.html

# merge a specific/selected commit/file/changes – http://technosophos.com/content/git-cherry-picking-move-small-code-patches-across-branches/
$ git cherry-pick 5d3e1b6

# only merge if theres no conflict, fast forward
$ git merge --ff-only [branch]

# Git command line for merging without committing
# http://stackoverflow.com/questions/12912985/git-visual-diff-between-branches#answer-16790950

git merge --no-commit --no-ff branchB

$ git reset --merge #cancel the merge

# want to change the order of commits, add additional one, combine, previous, remove/delete
$ git rebase -i [branch]~[number of commits]
# if confict you may need to $ git mergetool
$ git rebase --continue # to continue with rebase
$ git rebase --abort # to quit rebase

#rebase, https://www.youtube.com/watch?v=Ypi4Kwx0GJw
#when on a different branch
$ git rebase [name of branch to go under current checked out branch]

#how many commits per file
$ git ls-files | xargs wc -l

#adding patches in git
, http://ariejan.net/2009/10/26/how-to-create-and-apply-a-patch-with-git/
#on the new branch

$ git format-patch master --stdout > newpatch.patch #what this does is get the difference between the branches into a text file

#back on the master branch

$ git am < newpatch.patch

#if error
$git am --skip

#rename a commit
git commit –amend
or
git commit –amend -m “Your new message here”

#unstage a file
git reset — <file>

http://git-scm.com/book/en/Git-Basics-Tagging
$ git tag
$ git tag v2.0

# when trying to git clone a repository in github so you can edit(ssh) on a new computer you need to create a key
$ ssh-keygen
Enter file in which to save the key (/home/sock/.ssh/id_rsa): (enter)
Enter passphrase (empty for no passphrase): (enter)
Enter same passphrase again: (enter)
#get key:
$cat ~/.ssh/id_rsa.pub
#then go to https://github.com/settings/ssh and add the ssh key

#serving git
http://toroid.org/ams/git-website-howto
$ git push web +master:refs/heads/master

http://pythonsweetness.tumblr.com/post/52587443706/devs-please-stop-serving-git-to-the-outside

There are two types of repositories: bare and non-bare
non-bare you cannot push to a working copy, thus: [remote rejected] master -> master (branch is currently checked out), cannot push to master

Bare repositories do not have a working copy and you can only push, pull and fetch to them.
Those are the types of repositories you get in Github! If you want to create a bare repository, you can use

$ git init --bare

to change from normal to bare

$ git config --bool core.bare true

# add this block of code to the end of .git/config to not have to specify the branch and remote repository
# everytime you push or pull
[branch “master”]
remote = server
merge = refs/heads/master

# Find/Search a String in the Entire Git History
git rev-list –all | xargs git grep -F ”

# removing sensitive data, passwords, keys and things like that
http://code.tutsplus.com/tutorials/git-tips-from-the-pros–net-29799#highlighter_961797

# good resource:
http://code.tutsplus.com/tutorials/git-tips-from-the-pros–net-29799

# host git on dropbox
https://github.com/anishathalye/git-remote-dropbox

### using git to deploy to production server
http://stackoverflow.com/questions/279169/deploy-a-project-using-git-push/3387030#answer-327315
http://stackoverflow.com/questions/3221859/cannot-push-into-git-repository#answer-12065924
http://stackoverflow.com/questions/9227282/git-push-to-checkout

Best Practice: Software Versioning

You should start with version 1, unless you know that the first version you “release” is incomplete in some way.

As to how you increment the versions, that’s up to you, but use the major, minor, build numbering as a guide.

It’s not necessary to have every version you commit to source control as another version – you’ll soon have a very large version number indeed. You only need to increment the version number (in some way) when you release a new version to the outside world.

So If you make a major change move from version 1.0.0.0 to version 2.0.0.0 (you changed from WinForms to WPF for example). If you make a smaller change move from 1.0.0.0 to 1.1.0.0 (you added support for png files). If you make a minor change then go from 1.0.0.0 to 1.0.1.0 (you fixed some bugs).

If you really want to get detailed use the final number as the build number which would increment for every checking/commit (but I think that’s going too far).

>Installing Kdiff3 version control mergetool for Git

>kdiff3 is a great GUI mergetool for git. However the installation is more tedious in Windows compared to Linux. Below is instruction on how to install it in Windows.

Download and install program:
http://sourceforge.net/projects/kdiff3/

Add kdiff3 as your Git mergetool
From Git Bash, run
$ git config –global merge.tool kdiff3

Open the file repository/.git/config
and paste the code below

[merge]    
    tool = kdiff3
[mergetool "kdiff3"]    
    path = C:/Program Files/KDiff3/kdiff3.exe    
    keepBackup = false    
    trustExitCode = false

tags:
git mergetool kdiff3 windows
kdiff3 mergetool is not available
better than vimdiff