• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 446
  • Last Modified:

first few commands for git?

Hi Experts,

I just did a git svn clone command from my svn repository.  I then worked a bit on the code and have some changes locally that I would like to start another git branch for, before adding these changed files to the git branch.  Could you help me with:
1-  command to create the new branch (considering that I have local mods after initial clone)
2-  add the modified files (since the initial clone)
3-  commit to the branch
4-  revert to normal svn branch.

Thank you very much!
Mike
0
thready
Asked:
thready
  • 3
  • 3
1 Solution
 
threadyAuthor Commented:
I tried the git extensions for explorer - I tried "Create branch" and I get an error that says:

The following untracked working tree files would be overwritten by checkout (with a whole bunch of files).

Why would they be overwritten?
0
 
evilrixSenior Software Engineer (Avast)Commented:
1-  command to create the new branch (considering that I have local mods after initial clone)

Heh. The general idea is you back the branch first :)

First of all commit any changes to your current (master?) branch

git commit -am "some message"

Then create and checkout your new branch
git checkout -b <branchname>

Your new branch will now be in sync with the previous branch. You can now return back to the previous (master?) branch and reset it back to the original pre-commit state and your new branch will have all the changes.

git checkout <oldbranch>
git reset --hard HEAD^

2-  add the modified files (since the initial clone)

To add all the new files just do

git add .

To add a specific file

git add <filepath>

3-  commit to the branch

git commit -am "commit message"

4-  revert to normal svn branch.

If you mean revert back to the state that reflects the svn repo but the way you'd normally do this is to reset back to the origin/<branch> tag. Assuming you are in master of a tracking branch and you want to reset back to the remote master state you'd do this...

git reset --hard origin/master

Not sure if that will work from an svn repo though as I don't think a direct clone counts as a tracking branch. If that isn't the case then you could look at the git log and find the revision id you want to revert to, something like...

git log

find the revision id and then

git reset --hard <revision-id>
0
 
evilrixSenior Software Engineer (Avast)Commented:
>> I tried the git extensions for explorer - I tried "Create branch" and I get an error that says:
I gave up on all the GUI tools for git (except those that come with it) as they are all problematic. They hide the power (and the fact that doing everything from the command line is pretty trivial) of git behind buttons that often obfuscate what's happening. If  you really want to use a GUI I'd recommend Git Extensions.

http://code.google.com/p/gitextensions/

There is also a Tortoise-Git but I didn't really find that at all useful when working with Git.

>> The following untracked working tree files would be overwritten by checkout (with a whole bunch of files).
>> Why would they be overwritten?

There are 2 ways to create a new branch

git branch <branchname>
git checkout -b <branchname>

The former creates the branch but leaves you in the current branch, whereas the latter will change you to the new branch. If you perform the latter (and it sounds like this is what your GUI is doing) and you have uncommited changes they would get lost (since they don't exist in the new branch since it would be a reflection of only commited changes). For that reason you either need to commit of stash before changing to a new branch.

http://book.git-scm.com/4_stashing.html

You might find this tutorial helpful: http://git.or.cz/course/svn.html

Also, another GUI I quite like is SmartGIT. It's not free for commercial use though... but it isn't too bad and if you're just working on your own stuff it's worth looking at.

http://www.syntevo.com/smartgit/index.html

That all said, learn to use the git command line tool. Unlike the svn command line too (which is just painful) the git one is actually quite simple and is generally a lot quicker to use. Also, you get more of a feel for what you're actually doing so things generally make a lot more sense when you get an error :)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
threadyAuthor Commented:
Thanks a lot - I'm about to start using it finally.  My fingers are crossed!  :o)
0
 
evilrixSenior Software Engineer (Avast)Commented:
Heh... good luck -- I doubt you'll ever consider using SVN again once you've started using Git in anger. I never could!
0
 
threadyAuthor Commented:
thanks evilrix - I have another question that I think you'd get super easy points with if you're interested:

http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_27308409.html#a36538575

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now