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.

  • Is there an GIT alternative for SVN Externals?
  • CocoaPods: point to a branch in pod spec
  • Move existing, uncommited work to a new branch in Git
  • Auto deployment with Git and Rails, How does it work?
  • Split a git branch into two branches?
  • How to update my version of git on OSX 10.8
    • 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?

  • Usage of 'pull' command in Jgit
  • git setup for backup & sync between 2 computers
  • What does the brown asterisk icon on a file mean in Eclipse?
  • Git:nothing added to commit but untracked files present
  • How to set specific path permissions using Git?
  • Is a bidrectional Git<->Svn Sync (both writable) possible?
  • 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)

    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 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.