Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


first few commands for git?

Posted on 2011-09-08
Medium Priority
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 2000 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: 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.


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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

610 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