git stash

I feel like stash is another commits tree, but only one node. This is used for temporarily store away your current work directory.

When you type

git pull

This will firstly check if your work directory matches your commits or your stash. If not, it will gives you some error

file foobar not up to date, cannot merge.

Then, if you git stash your current work directory, if will allow you pull

git stash
git pull
git stash pop

git stash pop throws away the (topmost, by default) stash after applying it, whereas git stash apply leaves it in the stash list for possible later reuse (or you can then git stash drop it).

reset vs checkout

First I need to say, I understand the terminologies as

work directory: your current source code

stage: a cache copy of the code; “commit” usually are from this cache

commits: more officially history records of your previous code and those records are made through your “git commit” commands



Each branch has a tip pointer like “master”,”development”. When you do

git checkout <branch_name>

it moves the current pointer (unfortunately, this pointer is called “HEAD”) to the branch tip of <branch_name>. This changes show up in your work tree (which refers to your real coding files).

Similarly, the following command will bring your code back to a previous specified time point.

git checkout <reference>

As you still have all your commits, you can revert your coding files back to the another branch tip namely the <branch_name>.

However, this is different for git reset

git reset <to_point>

reset, will move the tip pointer <branch_name> to <to_point>., whose default value is HEAD (current position).

Then you lost all the commits between <to_point> and the “old” <branch_name>.

–soft– means change the commits only,

–mix– (default) change both commits and stage, but leave your current source code untouched

–hard–change everything and you will have no way to revert this change





Git init

initialize the git project

git init

then add the files you want to track

git add <filenames>

create records by

git commit -m "message for this commit"

create a new remote called origin located at (I understand “remote” as a symbolic link pointing to the remote directory “<user_name>/<app_name>.git”)

git remote add origin<user_name>/<app_name>.git

after you have the “remote”, you can “push” the commits to it, where master is the main branch of your project.

git push origin master


Github notes

“Changes not staged for commit” ?

The files are already added to Git to be monitored, but the changes are not added to be committed. To be add, it needs

git add <filename>

This allows the changes to be recorded for multiple commits separately.

For example, let’s say you have file a, file b . You modify file a and file b , but you don’t want all of them to be in one single commit. You type

git add a
git commit a -m "fixes in a"
git add b
git commit b -m "fixes in b"

As a side note, if you want to commit everything you can just type

git commit -a