Add, commit, stash #
Staging files #
Git lets you to choose which modifications will be part of your next commit.
First, run
git status
This will show which files have been added or modified since the last commit on the current branch (if any). In order to add (some of) these files to the next commit, you need to stage them.
If you want to stage all these files, from the root of the repository, run
git add .
Hint. You can create a .gitignore file to indicate files of folders that should never be staged.
This allows you to use
git add .
without staging by accident compiled files, IDE-generated files, etc.
Alternatively, to stage a specific file (or the content of a specific folder, recursively) run
git add <relative/path/to/file>
At any moment, you can check which files have been staged with
git status
You can also unstage all staged files with
git reset .
And unstage a single file with
git reset <relative/path/to/file>
Commit #
Once you have staged your file, you can commit with
git commit -m "<commit message>"
If you do not add the -m "<myMessage>"
option to your command, then git will open a text editor where you can type a commit message.
If this happens, then type your commit message, save and close the file.
Warning. By default, on most operating systems, git opens vi as a text editor. I you have never used vi, we recommend selecting another default text editor.
Stash #
git stash
temporarily reverts all modifications made to your repository since the last commit.
To apply them back, run
git stash pop