How not to forget to add files

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?

  • concept of bare shared repository in git
  • What's the best way to checkout selected files and folders from a bare git repository on linux?
  • git svn clone update_ref failed for ref, refusing to update ref with bad name
  • Move branch to a different repository while preserving its commits but aggregating remaining history
  • How to start a github repository with a few versions that are in zip files
  • Git unable to push to remote repository: “Read-only file system”
  • Merge separate git repositories into one repository, organized by folders
  • Merging branches on subversion
  • 3 Solutions collect form web for “How not to forget to add files”

    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
    

    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.

    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\]'
    
    Git Baby is a git and github fan, let's start git clone.