0

I'm currently trying to push some of my project files to github but I've been banging my head against the table now trying to figure out what is going wrong. Any help would be greatly appreciated.

What I do is I first created a new folder in my c:/ directory called cs188 and put all the files that I want committed in that folder. MY goal is to push the whole cs188 folder I created to github.

In git bash, I type:

(in the cs188 folder):
git init

git add .

git commit -m "first commit"

Now I add the remote

 git remote add origin https://github.com/my_username/myrepos.git

(myrepos is the name of my repository on github)

Then afterwards I type:

git push origin master

I get a warning saying that "the tip of my current branch is behind its remote counterparts. Merge the remote changes before pushing again".

So now I type:

git pull origin master

But once this is done, my whole new folder has been replaced with the contents of my repos.
And once I type git push origin master, now and log onto my github account, nothing has changed or been added.

Does anyone have any idea what I'm doing wrong here?
Why is my new folder getting replaced with all the folders in my repository?
What should I do instead to get rid of "the tip of my current branch is behind its remote counterparts", and have my whole cs188 folder show up on github?

Any help is appreciated, I'm just completely frustrated with github right now and could really use some help.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
flicflac
  • 131
  • 1
  • 5

1 Answers1

2

One easiest way is to:

  • clone your new empty GitHub repo
  • add your file in that local clone, and commit
  • push

The first push would be done with:

 git push -u origin master

After that, a simple git push will be enough.
See "Git: Why do I need to do --set-upstream all the time?".

Note: if your Github repo wasn't empty, the idea is still valid: clone it and add your files in it.
Otherwise, you would need to follow "Cannot pushto github, keeping saying need merge".

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Hi VonC, thanks for the quick response. Could you give me the exact commands to do the three steps you mention above? – flicflac Jan 21 '13 at 08:53
  • Also, what do you mean by clone my new empty github repo? My current github repo is not empty and contains a bunch of other files as well. – flicflac Jan 21 '13 at 08:56
  • @flicflac the first one is `git clone https://github.com/my_username/myrepos.git cs188`. The `cp`, `add` and `commit` are like in your question, and you don't need to add a `remote origin` (it has been added by the `git clone`). Note: the all content of your Github repo will be the one of `cs188`: you won't have a directory `cs188`. If you want one, you need to copy your files in a `cs188` directory *within* your local clone. – VonC Jan 21 '13 at 08:59
  • @flicflac just saw your last comment. As I say at the end of my answer, you can still clone your GitHub repo: `git clone https://github.com/my_username/myrepos.git github`, and copy `cs188` inside it. – VonC Jan 21 '13 at 09:00