git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Automatically Add .gitignore Files
@ 2017-02-08 19:05 Thangalin
  2017-02-08 23:39 ` Junio C Hamano
  2017-02-09 10:03 ` Duy Nguyen
  0 siblings, 2 replies; 5+ messages in thread
From: Thangalin @ 2017-02-08 19:05 UTC (permalink / raw)
  To: git

I frequently forget to add .gitignore files when creating new .gitignore files.

I'd like to request a command-line option to always add .gitignore
files (or, more generally, always add files that match a given file
specification).

Replicate

0. git init ...
1. echo "*.bak" >> .gitignore
2. touch file.txt
3. git add file.txt
4. git commit -a -m "..."
5. git push origin master

Expected Results

The .gitignore file is also added to the repository. (This is probably
the 80% use case.)

Actual Results

The .gitignore file is not added to the repository.

Additional Details

At step 4, there should be a prompt, warning, or (preferably) either a
command-line or configuration option to add the .gitignore file prior
to commit, automatically. Such as:

git commit --include-all-gitignore-files -a -m "..."

Or:

echo "**/.gitignore" >> .git/config/add-before-commit

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Automatically Add .gitignore Files
  2017-02-08 19:05 Automatically Add .gitignore Files Thangalin
@ 2017-02-08 23:39 ` Junio C Hamano
  2017-02-09  0:01   ` Stephan Beyer
  2017-02-09 10:03 ` Duy Nguyen
  1 sibling, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2017-02-08 23:39 UTC (permalink / raw)
  To: Thangalin; +Cc: git

Thangalin <thangalin@gmail.com> writes:

> I frequently forget to add .gitignore files when creating new .gitignore files.
>
> I'd like to request a command-line option to always add .gitignore
> files (or, more generally, always add files that match a given file
> specification).

That is essentially what "Untracked files" listing in the editor
buffer given to you when you type "git commit" is about.  By not
saying you ignore .gitattributes, .gitignore, .gitmodules, etc., you
are reminded if you forgot to add them.  "git status" does the same,
and perhaps you want to make it a habit to run it before committing.

I am tempted to say that there should be a way to somehow forbid use
of the "-m" option to "git commit" by default, until the user gains
more familiarity with use of Git.  That way, they will learn to pay
more attention to the "Untracked" and "Changes not staged" sections
;-)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Automatically Add .gitignore Files
  2017-02-08 23:39 ` Junio C Hamano
@ 2017-02-09  0:01   ` Stephan Beyer
  0 siblings, 0 replies; 5+ messages in thread
From: Stephan Beyer @ 2017-02-09  0:01 UTC (permalink / raw)
  To: Junio C Hamano, Thangalin; +Cc: git

> I am tempted to say that there should be a way to somehow forbid use
> of the "-m" option to "git commit" by default, until the user gains
> more familiarity with use of Git.

Since I am using git, I am tempted to say that "git commit -m" should be
abolished. If I tell somebody how to use git, I never mention "git
commit -m". Unluckily they find it out themselves... ;D

The typical observations I have when people use "git commit -m":

 * The commit messages are either too long (in one line!) or
   too meaningless.

 * People don't check what they added and commit wrong stuff.

 * People make fast temporary commits with "asdafsd" commit messages.
   Then they get distracted for some time and work on another branch.
   When they turn back to the old branch they don't know what "asdafsd"
   was...

Thanks to git rebase -i and/or git commit --amend, it is all not too bad
after all ;D

Best
  Stephan

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Automatically Add .gitignore Files
  2017-02-08 19:05 Automatically Add .gitignore Files Thangalin
  2017-02-08 23:39 ` Junio C Hamano
@ 2017-02-09 10:03 ` Duy Nguyen
  2017-02-09 17:25   ` Thangalin
  1 sibling, 1 reply; 5+ messages in thread
From: Duy Nguyen @ 2017-02-09 10:03 UTC (permalink / raw)
  To: Thangalin; +Cc: Git Mailing List

On Thu, Feb 9, 2017 at 2:05 AM, Thangalin <thangalin@gmail.com> wrote:
> I frequently forget to add .gitignore files when creating new .gitignore files.
>
> I'd like to request a command-line option to always add .gitignore
> files (or, more generally, always add files that match a given file
> specification).
>
> Replicate
>
> 0. git init ...
> 1. echo "*.bak" >> .gitignore
> 2. touch file.txt
> 3. git add file.txt
> 4. git commit -a -m "..."
> 5. git push origin master
>
> Expected Results
>
> The .gitignore file is also added to the repository. (This is probably
> the 80% use case.)

This is a general problem to new files, not .gitignore alone. Can we
accomplish something with some hook? At the least I think we should be
able to detect that .gitignore is not detected and abort, prompting
the user to add it. It's easier to customize too, and we don't have to
cook ".gitignore" in the code.

I'm not sure if we tell the hook "this is with -m option" though..
-- 
Duy

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Automatically Add .gitignore Files
  2017-02-09 10:03 ` Duy Nguyen
@ 2017-02-09 17:25   ` Thangalin
  0 siblings, 0 replies; 5+ messages in thread
From: Thangalin @ 2017-02-09 17:25 UTC (permalink / raw)
  To: Duy Nguyen; +Cc: Git Mailing List

Hi Duy,

> This is a general problem to new files, not .gitignore alone. Can we

The difference, to me, is that a ".gitignore" file is not part of what
I'm developing. It's an artifact for git configuration. While a
.gitignore file is not always pushed to the repository, I imagine that
in most situations, it is.

Whereas when a "new" file is created, there are plenty of situations
where it shouldn't be added and thus a warning would be superfluous,
or an automatic add would be undesirable.

To solve the problem, generally, for new files while giving the user
the ability to specify exactly what "new" files should be
automatically added to the repository, something like the following
would work:

echo "**/.gitignore" >> .git/config/add-before-commit

> and perhaps you want to make it a habit to run it before committing.

Right, because software shouldn't automate repetitive tasks and humans
are never prone to forget? ;-)

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-02-09 17:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-08 19:05 Automatically Add .gitignore Files Thangalin
2017-02-08 23:39 ` Junio C Hamano
2017-02-09  0:01   ` Stephan Beyer
2017-02-09 10:03 ` Duy Nguyen
2017-02-09 17:25   ` Thangalin

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).