6

I situation that often occurs for me is :

  • I create a new file
  • I modify an existing file

Everything compiles, I'm proud of myself.

  • I commit
  • I push it to the server

My teammates pull : They can't compile because a file is missing. They all want to kill me.

The question is, how to make sure I've added all needed files?

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
Titouan56
  • 6,932
  • 11
  • 37
  • 61

3 Answers3

10

I always do git status before pushing, to make sure I did not miss anything in the "to add" file list.

The output is quite explanatory:

$ git status
On branch XXX
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   YYY

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

    ZZZ1
    ZZZ2

Then, it is also good to have some kind of staging environment that is shared with everyone. This way, when you push you also make sure the staging environment is also stable, so others will have a working example of your recent changes:

$ git checkout staging
$ git pull --rebase
$ git merge <your_branch>
$ git push
fedorqui
  • 275,237
  • 103
  • 548
  • 598
8

As a best practice you should always check git status before committing.

You can modify any of the git hooks (pre-commit, post-commit) to print out to screen list of your untracked files so you will see it and wont miss it.

use this command to print out untracked files:

git ls-files --others --exclude-standard

Another solution:
you can write an alias that does it for you as well so you will not forget to do it next time.

Nice to have:

set your color settings to display your changes in color, meaning

  • red - deleted files
  • green - added files
  • magenta - modified files

So it will be easier for you to track changes.

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • What would be interesting is to use that to prepend the list to the commented message you get in the commit message editor but I don't know if the commit template can serve this purpose. – Denys Séguret May 20 '15 at 10:06
4

I like to have my bash prompt warn me if I have a dirty state and which branch I'm working on.

/tmp/myrepo (master) $ touch newfile.txt
/tmp/myrepo (master %) $ git add newfile.txt 
/tmp/myrepo (master +) $ git commit -m 'added newfile'
[master 9fe6399] added newfile
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 newfile.txt
/tmp/myrepo (master) $ 

This is achieved by adding the following to .bashrc

export GIT_PS1_SHOWDIRTYSTATE=true
export GIT_PS1_SHOWSTASHSTATE=true
export GIT_PS1_SHOWUNTRACKEDFILES=true
export PS1='${debian_chroot:+($debian_chroot)}\[\033[01;33m\]\w\[\033[01;32m\]$(__git_ps1) \[\033[01;36m\]$ \[\033[00m\]'
crea1
  • 11,077
  • 3
  • 36
  • 46