Showing posts with label git. Show all posts
Showing posts with label git. Show all posts

Git: untracked working tree files and branch checkout


Untracked working tree files are basically just new files that have never been commited to your Git repository. They might prevent you from switching to another branch. You can see errors similar to this one:

$ git checkout <branch>

error: The following untracked working tree files would be overwritten by checkout:
Please move or remove them before you can switch branches.

Workaround A:
You can manually remove untracked files before checking out another branch. If you actually need the files you might want to move them to separate "backup" folder instead of deleting.

It seems OK if the number of untracked files is low. Otherwise it may be a bit of a hassle if you have a lot of them.

Workaround B:
Add the untracked folders and files to git ignore properties, for example:

One thing to note is that git ignore has no effect on files that have already been committed (which might be in a different branch) so they can be removed by running the following command:

$ git rm --cached

Downside of this solution is that they are just ignored from now on and you might need to add them back in the future.

Workaround C:
This is probably the best if you don't care about the files - just delete them all automatically by running the following command:

$ git clean -d -fx ""

-d also remove untracked directories
-f force it to run
-x also remove files ignored by git (.gitignore)
Be careful with -x as it might remove your project IDE specific settings and everything else that is ignored by git

You can find more details about git clean here:

That's it :)

How to: migrate SVN repository to Git and keep history

Hi all,

Today we are going to cover topic about moving from Subversion to Git and ways to copy / migrate SVN data to Git repository (so we can keep the history of commits)

I would recommend doing the migration process using Linux OS as it seems to be much faster than on Windows OS (at least when I was testing it) - this is especially for large repositories.

  • Create "authors" file that relates to SVN repo commit authors. It should be in the following format:
username1 = user_firstname user_lasname <user_email>

username2 = user_firstname user_lasname <user_email>
and so on...

  • Tell Git about it: 
git config --global svn.authorsfile <path_to_authors_file>

  • Init Git repository with SVN reference:
git svn init <svn_repo_url> --stdlayout --prefix=svn/

  • Review/edit .git/config file, it should look like this:
[svn-remote "svn"]
url = <svn_repo_url>
fetch = trunk:refs/remotes/svn/trunk
branches = branches/*:refs/remotes/svn/*
tags = tags/*:refs/remotes/svn/tags/*
authorsfile = /path/to/authors.txt

If the SVN repository is large you might want to limit the fetch to only some branches and tags. If so you can do it by specifying them in the .git/config file, for example:
[svn-remote "svn"]
url = <svn_repo_url>
fetch = trunk:refs/remotes/svn/trunk
branches = branches/{feature_branchA,old_branchB,branch_test}:refs/remotes/svn/*
        tags = tags/{tagA,tagB,tagC}:refs/remotes/svn/tags/*

  • Fetch the commits: git svn fetch
Occasionally it may stop due to some random errors or due to unknown commit author. In that case you can add new row/entry in your authors. You can also try to clear memory by running:
git gc OR/AND git svn gc

To resume and continue the fetch run: git svn fetch

  • After a while depending on the repository size it will finish and you can view all available SVN branches by running the command: git branch -a

  • Next step is to create Git branches and tags to the corresponding SVN branches and tags. For each SVN branch run the following command:
git checkout -b <BRANCH_NAME> svn/<BRANCH_NAME>

  • The similar thing for tags, but you might choose to leave tags as branches whatever you prefer:
git checkout -b <tag_TAGNAME> svn/tags/<TAG_NAME> // creates a branch for SVN tag
git checkout master
git tag <TAGNAME> <tag_TAGNAME> // create git tag to that branch
git branch -D <tag_TAGNAME> // delete the previously created branch, tags stays

Repeat for each SVN tag.
  • Switch to the master and create .gitignore file:
git svn show-ignore > .gitignore
// edit .gitignore to manually add whatever you want to ignore
git add .gitignore
git commit -m 'Convert svn:ignore properties to .gitignore.'

Alternatively and/or additionally you can set ignore globally for that repo:
git svn show-ignore >> .git/info/exclude 
  • define remote Git repository so it's added to the .git/config
git remote add origin <GIT_REPO_URL>
  • push everything to the Git repository
git push -u origin -all // push all branches and changes to the repo named origin
git push --tags origin // push the tags as previous command ignores tags


A) If you want to add some branch or tag later you can do it by telling about it in .git/config:
[svn-remote "branch_MyBranchX"]
url = <SVN_REPO_URL>branches/MyBranchX/

    fetch = :refs/remotes/svn/MyBranchX


  • Fetch it: git svn fetch
  • Create git branch for it: git svn checkout -b MyBranchX svn/MyBranchX
  • Push it: git push origin MyBranchX

B) If you want to update existing branch from SVN because your team has not switched SVN off yet and you want to sync later changes just fetch the changes:

git svn fetch OR git svn fetch <BRANCH_NAME>

Then switch to related Git branches and rebase:
git rebase svn/<BRANCH_NAME> // sync with the recent changes from SVN
git push origin <BRANCH_NAME>

This is it! Happy migrationg :)

Welcome to GIT - revisited


Git is getting more popular and it's really good. So here is a quick introduction how to get started with it.

First step is to install the tool - you can download it from the official website:

There are versions for many different OS such as Linux, Windows, Mac OS X and Solaris.

After installing it you should be able to open GIT bash where the fun begins :)

Set your user details such as name and e-mail - this will appear in the commits.
git config --global <your_username>
git config --global <your_email>

It's good to have nice merge tool. There are some supporting 3-way diffs and some usual 2-way diffs. Two of them are worth recommending at this point:

Once you choose your favourite you can set it up for Git using the following command:
git config --global diff.tool <your_diff_tool>

If you want to display the list of config settings use the command:
git config --list

Before you can start working with Git you should also set up your SSH keys. Follow our guide for setting them up:

Most common way of using Git is using the command line via Git Bash tool - and most of the users are OK with it. However there are some users who prefer graphic user interface - so good news is there are GUI tools for Git. Some of them are integrated in the development IDE such as for example Eclipse or NetBeans.
You can also install the dedicated tool such as for example:

That's it basically. Cheers!

GIT setup: basic configuration


After installing Git client it's ready to use right away. However there are few things you may want to consider setting up. Those are things like for example user name and e-mail address.

You can display current config values with the following command:
$ git config --list

Important Note
When setting configuration parameters you can set it either as global or local value. By default you are setting the local value. By using --global param it will be set-up globally which means it will be used for all of your projects unless overridden by a local setting.

Setting user name
$ git config --global "xuser"
$ git config "xuser"

Setting e-mail

$ git config --global
$ git config

That's it.

Git Error: Permission denied (publickey)


The other day I was trying to fetch the changes from the remote repo and the following error has been displayed:

$ git fetch origin

Agent admitted failure to sign using the key.
# Permission denied (publickey).

In this case the reason was that I've changed / switched between two different ssh keys. However if you got similar issues the problem has been fixed by telling ssh to use the key by running the following command:

$ ssh-add

That's it - problem solved :)