How to teach students not to use other people's work in an assignment or a thesis? When reading submissions by students, for example coding assignments or bachelor theses, I stumble upon code or text not originally written by the students themselves, usually not referenced properly (see the edit below). After being confronted with this, I often hear or read statements like:


"I did write it myself -- using a source, and making some of my own modifications."
"Wikipedia explains this topic very well. I didn't know that I am
not allowed to copy the article in my thesis. Wikipedia is 
even on my list of references!"
"Our code looks similar, because he helped me with some bugs I had."
Or that plagiarism in the methodology section is small and unimportant (original version).


I usually tend to see these statements as lame excuses, because I thought it would be common sense how not to plagiarize, but maybe they are right that they really do not know it better. It seems like they think the correct way to avoid plagiarism is to modify the source even more instead of doing it on their own in the first place.

Our usual approach to tackle this problem is to state that we do not want
plagiarism, search for indications of plagiarism and then have endless
discussion about it afterwards.

There are methods to circumvent this partially, for example by providing
individualized tasks, and our university also provides workshops that teach you for example how a reference list should be built, but I am searching for ideas for the everyday teaching (programming labs, supervising students writing a thesis...) to promote the mindset that taking the text or code from someone else and modifying it is not the correct way, especially when it comes to graded submissions or publications.

EDIT: After receiving multiple comments about what I am worried about is not plagiarism, I would like to explain this aspect a little more by means of some examples:


There is no reference at all: This is clearly plagiarism, period.
The reference is not sufficient: This is the Wikipedia case from above. Having only "Wikipedia, https://en.wikipedia.org/" in the list of references without any indication which part of the text is from which article and which part is written by the student does not help at all and is in my opinion nearly as bad as having no reference at all.
There is a proper reference: As others have noted, this is not plagiarism. Still, in the context of grading, we have to look deeper:


Written exam: Everyone should agree that a student should fail an exam if he copies the solution by another student even if he writes "This solution was copied from the student sitting next to me."
Code Assignments: I had cases where students wrote "I copied this part from ..., because I was not able to do it myself and the rest of the program would not work without it". This is totally fine for me, but the student should not expect to receive points for the copied part, but only for the other parts written by himself. The same holds for code copied from other sources and modified afterwards.
Lengthy text passages: This is the example of copying significant parts of a Wikipedia article, again. But this is already covered in several other questions.
It seems to me that you have an "Academic Integrity" issue as opposed to a "Plagiarism" issue. Academic Integrity covers many areas including:


Plagiarism
Collusion
Fabrication


and so on...

In my personal experience the biggest 'excuse' that students will plead is ignorance. What this causes is the following cycle:


students submit work
work is marked
issues are found
issues are discussed with student
student pleads ignorance
student is educated
(sometimes) student is allowed to resubmit


The problem here is that education comes after the crime, and any resubmissions can drastically delay students receiving marks and feedback (which feeds into other assignments).

Now I do not have a solution that will stop all cases of academic dishonesty and personally I do not think it is possible. If people want to cheat, they will. The key is to remove the accidental plagiarisms so that the focus is on the intentional cases.

To remove the ignorance excuse the answer is simple: education. Now you are already employing education as your solution, however, you are doing it after the submission. The key is to do it as soon as possible. Personally, I use part of my first tutorial class to teach the students what Academic Integrity is, and then get the students to work through some examples and questions. Lastly, I require them to complete an "Academic Integrity Quiz" which is regulated by our University Library. Before the students can gain access to our assignment submission boxes they MUST have scored 10/10 on that quiz (this is automated). Unlimited attempts are allowed on the quiz as well.

The solution above forces students to learn about Academic Integrity and thereby removes the "I didn't know" (ignorance) excuse.

I hope this helps.