60

I followed basic Git tutorial and added README file, which worked. Then I copied my project files to the same folder and tried to add them to repository by running

git add --all
git ci 'test' (my alias for commit)
git push origin master

and nothing got pushed.

What are the commands I should run to push my files to the remote repository (master)?

I tried to commit changes and run status but it says 'nothing to commit'. It does not recognize, that I copied lots of new files to that folder..

OK, so I type: git add . (get no response from console) then type to commit, and says no changes..

rahulroy9202
  • 2,730
  • 3
  • 32
  • 45
Stewie Griffin
  • 9,257
  • 22
  • 70
  • 97

5 Answers5

121

This is actually a multi-step process. First you'll need to add all your files to the current stage:

git add .

You can verify that your files will be added when you commit by checking the status of the current stage:

git status

The console should display a message that lists all of the files that are currently staged, like this:

# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#   new file:   README
#   new file:   src/somefile.js
#

If it all looks good then you're ready to commit. Note that the commit action only commits to your local repository.

git commit -m "some message goes here"

If you haven't connected your local repository to a remote one yet, you'll have to do that now. Assuming your remote repository is hosted on GitHub and named "Some-Awesome-Project", your command is going to look something like this:

git remote add origin git@github.com:username/Some-Awesome-Project

It's a bit confusing, but by convention we refer to the remote repository as 'origin' and the initial local repository as 'master'. When you're ready to push your commits to the remote repository (origin), you'll need to use the 'push' command:

git push origin master

For more information check out the tutorial on GitHub: http://learn.github.com/p/intro.html

ninjascript
  • 1,751
  • 1
  • 10
  • 8
  • @Stewie: After doing `git add `, what does `git status` show you? – jweyrich Aug 13 '11 at 00:55
  • I think it's a problem with a repository..I tried git push, but it says Error: repository not found, did you enter it correctly? How do I retype it?? I am so lost now.. – Stewie Griffin Aug 13 '11 at 00:59
  • @Stewie: did you try the [official tutorial](http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html)? I think it will help you to understand some concepts used by git. – jweyrich Aug 13 '11 at 01:01
  • so I run now git init under my folder it says 'Reinitialized existing Git repository in....' Then I try to follow steps, and says that repository not found.. – Stewie Griffin Aug 13 '11 at 01:03
  • I'm guessing you haven't connected your local repository to a remote repository yet. I've updated my answer to give you a better understanding of how that works. – ninjascript Aug 13 '11 at 01:05
  • @StewieGriffin Are you sure the git process is in the directory of the git repo, rather than where it starts. ie: `C:/project/git_repo` rather than `C:/` ? – TankorSmash Jul 22 '12 at 04:01
  • @ninjascript this works flawlessly! there's no more joy than watching your local file reflected in git repo! Cheers! – Gaurav Jun 04 '19 at 19:18
8

I had an issue with connected repository. What's how I fixed:

I deleted manually .git folder under my project folder, run git init and then it all worked.

Stewie Griffin
  • 9,257
  • 22
  • 70
  • 97
3

git add puts pending files to the so called git 'index' which is local.

After that you use git commit to commit (apply) things in the index.

Then use git push [remotename] [localbranch][:remotebranch] to actually push them to a remote repository.

James Chen
  • 10,794
  • 1
  • 41
  • 38
  • Minor correction: the [refspec parameter](http://www.kernel.org/pub/software/scm/git/docs/git-push.html) should be the local branch. Optionally, you can use `local_branch:remote_branch`, and a few other variations (even a commit SHA). – jweyrich Aug 13 '11 at 00:52
2

After adding files to the stage, you need to commit them with git commit -m "comment" after git add .. Finally, to push them to a remote repository, you need to git push <remote_repo> <local_branch>.

jman
  • 11,334
  • 5
  • 39
  • 61
  • I tried, but it says no updates.. It does not recognize, that I copied lots of new files to the folder.. and git push says 'everything is up to date', even I dont see my files on the repository.. – Stewie Griffin Aug 13 '11 at 00:43
  • No problemo, anything that helps ;-) – jman Aug 13 '11 at 00:46
  • how to get .git file inside my root project folder? – Kaveesh Kanwal Jun 22 '16 at 05:13
  • @Kaveesh : u need to run a git init 1st. You should take a look at the free ebook Pro Git which explains it pretty well ;) : https://git-scm.com/book/en/v2 – Melvin Dec 18 '17 at 19:20
1

my problem (git on macOS) was solved by using sudo git instead of just git in all add and commit commands