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.

  • How can I commit / remove a file starting by “:”?
  • How to keep two git repos synchronized?
  • Using Programmer's Notepad 2 as editor for git
  • Git for beginners: The definitive practical guide
  • Git clone in windows much slower than in linux
  • Git-hooks pre-push script does not receive input via STDIN
    • 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?

  • CMake External Project for Git Project
  • Git sends huge amount of data after branch
  • Connecting to GitLab repositories on Android Studio
  • How to import a git repository into another on a new branch
  • Git Remove unwanted commits from a Pull Request
  • DVCS Repo Design - separate dev from stable using branches or separate repos?
  • 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.