Merge to git repo

Jeg hadde to git repo’er på samme maskin, men i ulike kataloger.

Det som var ønskelig var å merge disse to repo’ene sammen til ett, slik at all historie ble tatt vare på. Dette kan gjøres da på følgende måte:

Git repo 1:


Gir repo 2:


cd /sti/til/repo1

git remote add -f repo2 /sti/til/repo1

git merge -s ours -no-commit repo2 repo2/master

git read-tree --prefix=dir-B -u repo2/master

git commit -m "kommentar til mergingen"

Dermed kan en slette ett av repoene, og samtidig ha en historikk over filene i et felles git repo.

git-cola in Windows 7

I have Windows 7 on my computer, but needed to run a git gui tool for our project. Searching on Google I found several, but they all were software for Linux. We have plenty of Linux Redhat servers, but no one running X window.

I installed then a Xming X server ( on my Windows 7 computer, and by configuring Putty (also a Windows program) and the sshd_config on the Linux server I could run git-cola and other Linux software in my Windows enviroment:


Putty configuration:

Connection -> SSH -> X11:

Enable X11 forwarding = true

X display location: location:0.0


Linux Redhat server configuration:

X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost yes


Also I noticed if I changed to another user in Putty (SSH) with:

sudo su –

then I wouldn’t be able to forward any X program. So, just after loggin in to the server in Putty with SSH, I had to start the program right away:







Move a local git repo to a remote repo

Challenge: one have a local git repo on a Linux server where a big bunch of commit’s have been done. Now one want to put all the files and commits on a remote server, for more easier sharing with other.

Here is how it might be done:

First create the remote repo. We use gitolite-admin, where we add typically:
# Explaination of the repo
repo path/to/remote/git/repo
RW+ = adminuser
RW = user1 user2 user3


git push

Now, since there is already a local git repo on the server with commits, we need to switch to the remote repo.
Check that there are no remote:
git remote -v
should not show anything, then:
git remote add origin

and possible this one too:

git branch --set-upstream master origin/master

What I had to do now, was to clone the remote repo I created with gitolite-admin in another directory, create a dummyfile, and push it. Then I could push and pull the local repo.
cd /tmp/
git clone
vim dummyfile
git add dummyfile
git commit -m "dummyfile" dummyfile
git push origin master

cd /back/to/the/local/repo/you/want/to/clone/to/remote
git pull
git push origin master

I guess there must be an easier way, but I am no Git master…

Or, one can also do it in this way:

cd folder/
git init
# make a lot of files, add, commit and so on..
# First push files to remote repo
git push --remote
# clone the remote repo into a new folder
cd ..
git clone folder2/
mv folder/ folder-old/
mv folder2/ folder/
# Test, everything ok? If so:
rm -rf folder-old/


Git is a tool that can help you track changes in your files, specially when you share your files with your friends on a Linux server.

Here is a very simple description:

log into your server
ssh foobarserver

go to your folder where you want to track files
cd to/your/folder/for-git-tracking/test/

create a local git repository
git init

Add your files to the local repo
git add

or add more files at once
git add .

Commit your changes to the repo, give a message -m, so that your friends can understand what you have done
git commit -m " first commit"

or commit all files in current directory (the character “.” is the directory where your files are.)
git commit -m "My files, snapshot" .

Now, start editing your file:



nano -w

After saving your changes, do:

git commit -m " I have changed an important part in this file"

git commit -m "My files, here is my explanation of the changes" .

Later on, you can do:

to see the log and the changes done
git log

did you forget to commit some files, or did someone change something?
git status