first few commands for git?

Posted on 2011-09-08
Last Modified: 2012-08-13
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!
Question by:thready
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3

Author Comment

ID: 36507922
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?
LVL 40

Expert Comment

ID: 36510550
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>
LVL 40

Accepted Solution

evilrix earned 500 total points
ID: 36510618
>> 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.

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.

You might find this tutorial helpful:

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.

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 :)
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!


Author Closing Comment

ID: 36537950
Thanks a lot - I'm about to start using it finally.  My fingers are crossed!  :o)
LVL 40

Expert Comment

ID: 36538593
Heh... good luck -- I doubt you'll ever consider using SVN again once you've started using Git in anger. I never could!

Author Comment

ID: 36538602
thanks evilrix - I have another question that I think you'd get super easy points with if you're interested:


Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question