1

I've been having a hard time with Git since I started using it. It's a learning curve that I want to beat. I've read thru the manuals and FAQs and several other sites but I'm still not seeing the behavior that I expect and hoping someone that's using VS2010 with GiHub can't give me the magic pointer I need.

These are the steps that I do to create a new project/repository.

1. Create new repository on GitHub - give it a name and create it

2. Create my solution in VS2010

3. Commit for first time

These are the steps that I take to commit the solution for the first time: (I have git and git extensions installed and I have a VS Toolbar created that allows me to pop up the git bash from within VS2010)

I click on the Git Console button I have created on the toolbar and I get the bash window and the current directory is the root directory of my solution

I then execute these commands to commit my solution to the GitHub repository on the GitHub site

1. git init - works fine

2. git add . - works fine

3. git commit -m 'First commit' - works fine

3. git remote add origin git@github.com:alfalfastrange/RepositoryName.git - works fine

4. git push -u origin master - I am then treated with a reject message and an error about fastforward etc, etc...

5. git pull origin master - works fine

6. git push -u origin master - the commit works and I can then see the whole solution online on GitHub

Now the problem I have is from here on out... if I make and changes to my solution I cannot get them into GitHub. For example, I delete files, add files and add code, etc and then I'm ready to commit all these changes

I've tried these sequences of events and had no luck

1. git add .

2. git commit -m 'Second commit' - adds changes to the local repository

3. git push -u origin master - Am given message that everything is up to date, I check the online repository and there have been no changes made

4. git pull origin master - Am told everything already up to date

5. git push -u origin master - Am given message that everything is up to date, I check the online repository and there have been no changes made

6. git push origin master - Am given message that everything is up to date, I check the online repository and there have been no changes made

It seems all the commit does from that point on is commit changes to the local repository and none of the commands I've tried will push the changes to the GitHub repository.

So at this point I'm slightly annoyed that it's not easier. With my Ankh SVN and Codesion setup all I have to do is click Commit or Update to push changes or pull latest from the online repository.

What am I missing? Because I want to be able to use Git successfully and without fear for all of my personal projects. Thanks in advance!

UPDATE

After running the git branch -avv command this is the result

enter image description here

Update 2

After running steps 1 - 6 with the -f added to step 3

enter image description here

Update 3

After running sequence of commands from answer

enter image description here

Which doesn't make any sense to me because we did all that already... I'm using only the Git Bash

CD Smith
  • 6,597
  • 7
  • 40
  • 66
  • What do you get from `git branch -avv`? – ellotheth May 23 '12 at 00:07
  • @ellotheth at what part of the sequence should that be called? – CD Smith May 23 '12 at 01:27
  • @ellotheth Just running it out of any sequence I see master 9f6237f Second commit – CD Smith May 23 '12 at 01:30
  • Anywhere in the sequence. Can you post the whole output? – ellotheth May 23 '12 at 02:22
  • @ellotheth .. that was the whole output – CD Smith May 23 '12 at 02:24
  • @ellotheth I updated question with the screenshot of the Git Bash screen after that command – CD Smith May 23 '12 at 02:27
  • So it was! Ok, do `git fetch origin` and run it again. You don't have the origin/master remote tracker set up, which is probably why the pulls/pushes aren't working. – ellotheth May 23 '12 at 02:31
  • @ellotheth I'd like to start this over from scratch, so I understand the commands and why...in my first set of 1 - 6 above is there anything there that should come out or be modified? – CD Smith May 23 '12 at 02:35
  • Yes: your `git remote add` line should have a -f flag (`git remote add -f yadda yadda`), or you should run `git fetch origin` afterwards. That will create the remote tracker(s) for the remote branches, so `git branch -avv` will show both your local branch and the remote tracking branches (e.g. `remote/origin/master`). – ellotheth May 23 '12 at 02:42
  • @ellotheth OK, I ran all 6 with the -f addition that you suggested and added a screenshot. git branch -avv gives me a lot more info now. Now that the solution is on GitHub (https://github.com/alfalfastrange/ReloadPartialViewFromAjax) If I make changes to the solution now, what sequence of commands should I follow for simple commits only, this is just single user commits (baby steps ya know) – CD Smith May 23 '12 at 02:49
  • @ellotheth It's my assumption that I should just be able to do git commit -m 'message' from here on out, but I'm also feeling like how will my changes get 'added' before committed? Do I need to keep track of every file change and explicitly add those? – CD Smith May 23 '12 at 02:55
  • You may want to check out some basic Git tutorials to get a feel for how the system works. http://gitimmersion.com/ is probably my favorite, but there are many more. The gitmagic chapter on remotes is also good: http://www-cs-students.stanford.edu/~blynn/gitmagic/ch03.html – ellotheth May 23 '12 at 03:01
  • @ellotheth I've actually read those during my researching but everything FAQ wise is all very "file" based. When using VS2010, I don't deal with files individually. I want to update the whole solution .. so do I run git add . again before each commit? This is where the actual answer to my question lies.. how to make subsequent commits – CD Smith May 23 '12 at 03:06

2 Answers2

1

Your first error message was certainly:

$ git push origin master
To ../remote/
 ! [rejected]        master -> master (non-fast forward)
error: failed to push some refs to '../remote/'

Which is normal, considering you had two parallel history going on: the one of GitHub (empty repo) and the one in your local repo. See also "I am not able to push on git?"
Once you you git pull, you merge the initial history of GitHub in your local repo, and make your first push successfully.

Now if the next git push (no need to add -u again by the way) reports that everything is up to date, check if you are not in a detached HEAD mode.
That would mean git branch would show no current branch (with '*' in front of it).
Other causes: "git says Everything up-to-date".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I've spent some time reading thru each of those articles and neither of them helped me with getting the right set of commands to commit. Have you used GitHub with VS2010 projects? And if so, what commands in what order did you use after the initial repo creation and subsequent editing of the project? – CD Smith May 22 '12 at 03:12
  • @CDSmith: no, not with VS2010 at the moment; I was reacting to an error message which looked like a "detached HEAD". – VonC May 22 '12 at 05:32
1

Just so people don't have to scroll through the comments:

Run git fetch origin to fetch the remote branches into your local repository. (You could also roll this step into the git remote add step with the -f flag.) Once that's done, you can track the remote master with your local master.

Once everything is hooked up, the simplest workflow looks like this:

# assuming an up-to-date branch and a dirty working copy
git add .   # Add changes under the current directory to the index
git commit -m "Commit message"
git push origin

You can roll the add and commit into one step as well:

git commit -am "Commit message" # Commit changes in tracked files to your local repo

Keep in mind I have no idea how Gitextensions works; it probably has its own plugin-y stuff for this.

ellotheth
  • 4,333
  • 2
  • 17
  • 29
  • That flow does not work either. Updating question with Git Bash Window. The command git push fails – CD Smith May 23 '12 at 11:52
  • Forgot the remote name, try `git push origin`. – ellotheth May 23 '12 at 13:52
  • That command gives me fatal: 'origin' does not appear to be a git repository - which perplexes the crap out of me because we just made all that happen with the first commit and it worked out just fine.. ugh lol – CD Smith May 23 '12 at 13:54
  • I re-ran everything start to finish after closing and reopening git bash and it worked! Thanks, now I think I can handle it. – CD Smith May 23 '12 at 14:12