10

I am just a git starter, basically I clone a git repository and now I wanted to commit the changes that I made in a file. when I run the command git commit it says not a git repository,

So being a starter in git i just wanted to ask that do i need to run this command first - git init and then git commit? Or in between these some more steps to follow to commit the file?

I need to commit files on Bitbucket.

Screenshot-

enter image description here

Dennis van der Schagt
  • 2,404
  • 2
  • 27
  • 33
Trialcoder
  • 5,816
  • 9
  • 44
  • 66
  • I suggest checking out http://git-scm.com/documentation and http://gitref.org/index.html. They'll give you a good quick start :) – jeremyharris Jan 15 '13 at 18:59
  • Also, you do not need to `init` cloned projects, only new ones that don't have git versioning the files. – jeremyharris Jan 15 '13 at 19:00

2 Answers2

11

As jeremyharris said, the git documentation site and especially the online book there will get you up to speed on the basics.

A few quick notes that might get you past your initial issue.

git clone command is used to pull a copy (a clone) from an existing git repository. By default it creates a folder in the folder you execute it from that has a .git folder in it. The folder the cloning creates is your working copy and the .git folder is your local copy of the repository.

git clone is different than most other git commands. All (or most?) other git commands require the command to be executed within the working copy folder created by the clone. (Bare repositories are a bit different since they don't have working copies, but that shouldn't apply here.) So, after doing:

$ git clone <remote repo> <repo name> 

do:

$ cd <repo name>

to get into the working copy before executing any other commands. Executing commands outside of the working folder will get you the not a git repository message.

After making a change to a file, git add <filename> adds it to the index (marked to indicate ready to commit) and git commit -m '<commit message>' will then commit the changes.

7stud
  • 46,922
  • 14
  • 101
  • 127
David Culp
  • 5,354
  • 3
  • 24
  • 32
  • 2
    Just saw you screenshot, `cd wedding` before `git add .` and `git commit`. – David Culp Jan 15 '13 at 19:19
  • ..thx I changed the directory and initialize git and then add and commit and iot works for me :) – Trialcoder Jan 15 '13 at 19:25
  • thx for the comments..plz add this line in your answer .for future reference :) – Trialcoder Jan 15 '13 at 19:26
  • you should not need to `git init` on a folder that has been created by the `git clone` command. `git init` is used to create a new repository from an ordinary folder, which creates the `.git` folder. It doesn't hurt anything to run it again -- it just should not be needed. – David Culp Jan 15 '13 at 19:37
  • @Davis Culp, I edited your post to add in a missing '>' bracket, which was confusing me, and I thought I might as well throw in a couple of blank lines for good measure. Sorry for the intrusion. – 7stud Aug 24 '14 at 04:04
3

You need to add the change at first, use git add .

You can also check the status before adding, by using git status

EDIT

Just saw the comments about error. Yes that's correct. I neglect that.

Your problem is you need to cd the git folder at first.

After that, you still need to add as my answer above.

Billy Chan
  • 24,625
  • 4
  • 52
  • 68
  • 2
    if git says `not a git repository`, it's obviously a problem of being in the wrong folder. – Nevik Rehnel Jan 15 '13 at 18:59
  • @BillyChan..so i dont need to run git init command? I can directly execute this add command ?? – Trialcoder Jan 15 '13 at 18:59
  • @NevikRehnel I just created a folder and run git clone command in the directory ..nothing else..so does it means i need to run git init command in this directory first before executing this add command ? – Trialcoder Jan 15 '13 at 19:01
  • @BillyChan I just added my screenshot ..plz chk – Trialcoder Jan 15 '13 at 19:06
  • @user1594368: `git clone` by default creates a subdirectory for the newly created clone (you would have seen that if you had just looked into your folder). You should probably read a tutorial for git that explains the basic steps :) – Nevik Rehnel Jan 15 '13 at 19:07