99

I'm new to Git and is using for the very first time. I would appreciate if someone could help me out. I tried finding the answer at forums,but there are tons of commands that are coming out and not sure which one to use.

On the prod server, if I do the git pull, it is giving me the following error:

Untracked files: (use "git add ..." to include in what will be committed)

Optimization/language/languageUpdate.php
email_test.php
nothing added to commit but untracked files present (use "git add" to track)
Please move or remove them before you can merge.

I'm not too sure how to make it work. If I remove them, from where would it be removed. Appreciate your reply.

user4943236
  • 5,914
  • 11
  • 27
  • 40

6 Answers6

82

You have two options here. You can either add the untracked files to your Git repository (as the warning message suggested), or you can add the files to your .gitignore file, if you want Git to ignore them.

To add the files use git add:

git add Optimization/language/languageUpdate.php
git add email_test.php

To ignore the files, add the following lines to your .gitignore:

/Optimization/language/languageUpdate.php
/email_test.php

Either option should allow the git pull to succeed afterwards.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • Ok, if I add them, will it be added to the server or to my local? – user4943236 Nov 04 '15 at 03:34
  • Tricky question. If you use `git add`, then the files will become tracked by your Git repository. This means that they will appear in any branch either locally _or_ on the remote. If you don't want this to happen, use the `.gitignore` option. If you really don't even need the files, you can delete them. – Tim Biegeleisen Nov 04 '15 at 03:35
  • thank you, after doing this, it says: error: Your local changes to the following files would be overwritten by merge: Optimization/language/update.php Please, commit your changes or stash them before you can merge. – user4943236 Nov 04 '15 at 03:38
  • You added a new file, and Git detects this as a change. So you will have to commit this by doing `git commit -m 'Added update PHP script'`. – Tim Biegeleisen Nov 04 '15 at 03:40
  • Thank you, it worked. may I know if there is good tutorial on Git. – user4943236 Nov 04 '15 at 03:45
  • 2
    I personally like [this site](http://www.gitguys.com/), although there are many tutorials out there. Mastering Git is not so much about picking the right tutorial, it is about just getting experience using it. You've already done that today :-) – Tim Biegeleisen Nov 04 '15 at 03:47
  • Thanks, but the cost of experiencing Git is too much, could have cost me my job. lol – user4943236 Nov 04 '15 at 04:30
75

Also instead of adding each file manually, we could do something like:

git add --all

OR

git add -A

This will also remove any files not present or deleted (Tracked files in the current working directory which are now absent).

If you only want to add files which are tracked and have changed, you would want to do

git add -u

What is the difference between git add . & git add --all?

Community
  • 1
  • 1
Viv
  • 1,706
  • 1
  • 18
  • 27
  • i tried same thing but it is showing "warning: unable to access : permission denied".... – vishwaraj May 30 '18 at 05:22
  • Some people consider this a bad practice because, well, what files did you just add? You don't know. Your Bash command history will never serve as a useful log of your actions. You will be relying blindly on the effectiveness of your .gitignore, and you'll probably accidentally commit build artifacts like Makefiles when they're actually auto-generated (as is the case in some projects) – Scott Prive Nov 20 '18 at 22:02
  • @Crossfit_and_Beer I kind of agree with you, but if your gitignore is broken, primarily you'd want to fix that than going ahead and inconveniently adding each individual file or removing each file from the cache while using the broken gitignore. Also git status is your friend, just to be double check. – Viv Nov 28 '18 at 01:59
  • or you can use `git add .` making sure you include the `.` – Eoin Jun 10 '19 at 17:27
20

Please Follow this process

First of all install git bash and create a repository on git

1) Go to working directory where the file exist which you want to push on remote and create .git folder by

$ git init

2) Add the files in your new local repository.

$ git add .

Note: while you are in same folder make sure you have placed dot after command if you putting path or not putting dot that will create ambiguity

3) Commit the files that you've staged in your local repository.

$ git commit -m "First commit"**

4) after this go to git repository and copy remote URL

$ git remote add origin *remote repository URL

5)

$ git remote -v

Note: this will ask for user.email and user.name just put it as per config

6)

$ git push origin master

this will push whole committed code to FILE.git on repository

And I think we done

tgogos
  • 23,218
  • 20
  • 96
  • 128
Akshay Digrase
  • 438
  • 3
  • 14
  • 1
    This solve my problem, I use `git reset --hard master` to reset my "twisted progress", and do this solution, and it worked. Thanks!! – Michael Harley Sep 02 '18 at 09:54
4

In case someone cares just about the error nothing added to commit but untracked files present (use "git add" to track) and not about Please move or remove them before you can merge.. You might have a look at the answers on Git - Won't add files?

There you find at least 2 good candidates for the issue in question here: that you either are in a subfolder or in a parent folder, but not in the actual repo folder. If you are in the directory one level too high, this will definitely raise that message "nothing added to commit…", see my answer in the link for details. I do not know if the same message occurs when you are in a subfolder, but it is likely. That could fit to your explanations.

questionto42
  • 7,175
  • 4
  • 57
  • 90
2

Follow all the steps.

Step 1: initialize git

$ git init

Step 2: Check files are exist or not.

$git ls

Step 3 : Add the file

$git add filename

Step 4: Add comment to show

$git commit -m "your comment"

Step 5: Link to your repository

$git remote add origin  "copy repository link  and paste here"

Step 6: Push on Git

$ git push -u origin master
Abdur Rahman
  • 1,420
  • 1
  • 21
  • 32
1

If you have already tried using the git add . command to add all your untracked files, make sure you're not under a subfolder of your root project.

git add . will stage all your files under the current subfolder.

Uriel Hernández
  • 731
  • 3
  • 9
  • 23