Git Concepts
remote repo <-> local repo <-> staging area <-> working directory
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
Basic Git Commands
Creating & Getting Branching Inspection
init branch log
clone checkout show
merge
Basic Remote Sharing
status remote
add push
commit pull
mv, rm fetch
tag
Can I change the commit
message before or after push?
Can I change the commit
message before or after push?
$ git commit --amend
bonus: $ git rebase -i
Note: Never change your commit history
after push to a public repository!
How do I ignore files in a project? Some files
such as .log which shouldn't be include in every
project, can I ignore it in every projects?
How do I ignore files in a project? Some files
such as .log which shouldn't be include in every
project, can I ignore it in every projects?
$ vim .gitignore
... add the file and folder path that you don't want git to
track ...
$ vim ~/.gitignore_global
$ git config --global core.excludesfile ~/.gitignore_global
Bonus: git config --global --list
Remind: Don't add too much files in the globa excludesfile
Search commit message
git log -g --grep=<pattern>
-g, --walk-reflogs
Instead of walking the commit ancestry chain, walk
reflog entries from the most recent one to older ones.
--grep=<pattern>
Limit the commits output to ones with log message that
matches the specified pattern (regular expression).
Can I change the filename case in Git?
fatal: destination exists,
source=font.ttf, destination=Font.ttf
Can I change the filename case in Git?
fatal: destination exists,
source=font.ttf, destination=Font.ttf
git mv -f font.ttf Font.ttf
You have pushed a WordPress folder in the Github and pull it from
the server.
But you make a mistake, you want to
- keep the wp-config.php in the server
- remove it on the GitHub, so your colleagues won't get a copy of
the wp-config.php
You have pushed a WordPress folder in the Github and pull it from
the server.
But you make a mistake, you want to
- keep the wp-config.php in the server
- remove it on the GitHub, so your colleagues won't get a copy of
the wp-config.php
[On the server]
$ vim .gitignore
$ git commit -am 'ignore wp-config.php file'
$ git rm --cached wp-config.php
$ git commit -m 'remove wp-config.php'
$ git push
Clients: This feature worked well in the past.
Why does it not work properly today?
We: How do we use Git to quickly identify the
issue?
Clients: This feature worked well in the past.
Why does it not work properly today?
We: How do we use Git to quickly identify the
issue?
Use GitHub to:
search
history
blame
$ git checkout <commit-sha>
Can I undo a git
commit?
Preserve all changes as unstaged changes
$ git reset HEAD^
Preserve all changes
$ git reset --soft HEAD^
Discard all changes
$ git reset --hard HEAD^
You are on a branch called "development", and you received
an email from the client said this bug needs to be fixed
now! Hence, you tried to switch your branch to "hotfix" or
"master" to do a quick fix, but your working dirctory is
"dirty", what should you do?
You are on a branch called "development", and you received
an email from the client said this bug needs to be fixed
now! Hence, you tried to switch your branch to "hotfix" or
"master" to do a quick fix, but your working dirctory is
"dirty", what should you do?
$ git stash
$ git checkout master
... fix issue ...
$ git commit -am "fix issue #100"
$ git checkout development
$ git stash list
$ git stash pop
bonus: $ git stash apply stash@{0} $ git stash drop stash@{0}
The same code can also applied to the
following scenario.
After finishing the development, you suddenly
realized the you are developing a feature on
the WRONG branch. Can I save those
changes and apply those changes in the
correct branch?
Recommendations
Read the git ERROR message
Commit or lose it
Do one thing at a time (the smaller the
better)
Don’t modify any history after pushing to live
Practice together