Tag Archives: git

Migrating to a new GIT server


You’re decommissioning an old server, which just so happens to have your GIT repo on it.

How can you migrate it without losing the history?

From the NEW SERVER:

Make your new directory & set the permissions to your GIT_USER:

mkdir /opt/git/qa.git
chown git.git /opt/git/qa.git

‘su’ to GIT_USER on the server, and initialize the newly created directory

su - git
cd /opt/git/qa.git
git init --bare

From the EXISTING CLIENT (with most recent copy of repo), make new directory, ‘cd’ into there and initialize it

mkdir ~/git/qa
cd ~/git/qa
git init .

Now, clone the existing repository INTO here.  It will not have the code, it’ll have the repository configuration.  Again, the command will be pointing at the ORIGINAL (soon to be decommissioned) server:

git clone --bare ssh://git@

You’ll see something like:

Cloning into bare repository 'qa.git'...
git@'s password:
remote: Counting objects: 841, done.
remote: Compressing objects: 100% (595/595), done.
remote: Total 841 (delta 292), reused 605 (delta 208)
Receiving objects: 100% (841/841), 21.52 MiB | 23.68 MiB/s, done.
Resolving deltas: 100% (292/292), done.

Then, it will create another <repo>.git directory in your “new” local directory (~/git/qa).  ‘cd’ into that

cd ~/git/qa/qa.git

Now, it’s your job to PUSH that config to the NEW server:

git push --mirror ssh://git@991.11.78.221/opt/git/qa.git

You’ll see something like:

Counting objects: 841, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (511/511), done.
Writing objects: 100% (841/841), 21.52 MiB | 0 bytes/s, done.
Total 841 (delta 292), reused 841 (delta 292)
To ssh://991.11.78.221/opt/git/qa.git
 * [new branch]      master -> master

When that’s done, you can ‘cd’ back a level & delete the <repo>.git file that the clone created.

cd ..
rm -rf qa.git

Now, you can either re-clone from the NEW server, seen HERE, or modify the existing .git directory’s config file to point to the new location:

vi ~/git/original_qa_repo_directory/includes/.git/config

and change the OLD server’s IP …

[remote "origin"]
        url = ssh://git@

… to the NEW server’s IP:

[remote "origin"]
        url = ssh://git@991.11.78.221/opt/git/qa.git

Now, issue a ‘git pull’ and you should be all set!

$ git pull
Already up-to-date.


I changed the password for my git repo and now it’s failing authentication on a pull

On my primary machine that’s always locked, I cache my password for some repos.  I just do.

So, after being forced to change the password to a (https!) repo, I tried a pull and it just happened to me.  This doesn’t impact ssh public key authentication.

$ git pull
remote: Invalid username or password. If you log in via a third party service you must ensure you have an account password set in your account profile.
fatal: Authentication failed for 'https://bitbucket.org/me/repo/'

You have to reset your credential helper cache, like so:

$ git config --global credential.helper cache
$ git pull

Ah, now — prompted for username & password.  #verynice

Username for 'https://bitbucket.org': fakeusename_1  
Password for 'https://fakeusername_1@bitbucket.org': 
remote: Counting objects: 11, done.
remote: Compressing objects: 100% (10/10), done.

And, scene.

git clone config global reset author –what?

Ah, cloning a git repo again, for the first time.   Here’s me using bitbucket.org; it’s free for slackers like me.

OK, so first:

$ mkdir -p ~/git/bitbucketrepo

$ git init ~/git/bitbucketrepo

$ cd ~/git/bitbucketrepo

$ git clone https://full-address-as-seen-in-bitbucket

Cool, now I add a few scripts & am ready to ‘stage’ them with ‘add.’

$ git add .

Unfortunately, this machine will get auto-assigned a name & email based on your login & some FQDN stuff.  I think we should change it.

$ git config --global user.name "Tom's Fedora 24 Workstation"
$ git config --global user.email tomblog@personalemail.email

Now, kick of a commit:

$ git commit -m "testing for blog"
[master 0e08355] testing for blog
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode ....

Now, time to ‘push’ it to bitbucket:

$ git push

AWW Crap, more stuff:

$ git push
warning: push.default is unset; its implicit value has changed in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the traditional behavior, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

When push.default is set to 'matching', git will push local branches
to the remote branches that already exist with the same name.

Since Git 2.0, Git defaults to the more conservative 'simple'
behavior, which only pushes the current branch to the corresponding
remote branch that 'git pull' uses to update the current branch.

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Then you’re prompted for your password & everything works.

HOWEVER — for the next ‘push’ – let’s adapt for the ‘new behavior:’

$ git config --global push.default simple

Make a test file & test again:

$ echo "BLOG TEST" > new_stuff.txt
$ git add .
$ git commit -m "blog test"
[master xxx] blog test
 1 file changed, 2 insertions(+)
 create mode ....
$ git push
Password for 'https://.....
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.

Looks good!

See you in a year when you need to do it again.


HOWTO: MOSH – when you need to SSH and there’s intermittent connectivity problems

Read about is here: https://mosh.mit.edu/

I loaded it up on RHEL 7.2, and here’s the process that I went through …

Add pre-requisite packages:
yum -y install git protobuf-c autoconf automake wget bzip2 gcc-c++ zlib-devel libutempter ncurses-devel openssl-devel net-tools

Run all of these commands:

wget http://protobuf.googlecode.com/files/protobuf-2.4.1.tar.bz2
tar -xf protobuf-2.4.1.tar.bz2
cd protobuf-2.4.1
./configure --prefix=$PREFIX
make install

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/root/lib/pkgconfig

$ git clone https://github.com/mobile-shell/mosh
$ cd mosh
$ ./autogen.sh
$ ./configure
$ make
# make install

echo "export LD_LIBRARY_PATH=/root/lib" >> ~/.bashrc ; source ~/.bashrc

firewall-cmd –add-port=60000-61000/udp