4. Git Workflow
4.1. Initialize repository
$ git init
Initialized empty Git repository in /home/devops/.git/
$ git init --bare
Initialized empty Git repository in /home/devops/.git/
$ find .
./config
./objects
./objects/pack
./objects/info
./HEAD
./info
./info/exclude
./description
./hooks
./hooks/commit-msg.sample
./hooks/pre-rebase.sample
./hooks/pre-commit.sample
./hooks/applypatch-msg.sample
./hooks/fsmonitor-watchman.sample
./hooks/pre-receive.sample
./hooks/prepare-commit-msg.sample
./hooks/post-update.sample
./hooks/pre-merge-commit.sample
./hooks/pre-applypatch.sample
./hooks/pre-push.sample
./hooks/update.sample
./refs
./refs/heads
./refs/tags
4.2. Clone repository
Protocols:
local filesystem
ssh
http
https
Sometimes ssh port is blocked (especially in public wifi)
HTTP is unsafe
HTTPS is the most robust option
$ git clone URL [dest dir]
$ git clone file:///...
$ git clone ssh://...
$ git clone https://...
$ git clone --recursive URL
$ git clone https://github.com/AstroMatt/book-devops.git
4.3. Pull
$ git pull --rebase
4.4. Add
$ git add .
4.5. Move
$ git mv [source] [destination]
4.6. Remove
$ git rm
$ git rm -fr
$ git rm --cached
4.7. Status
$ git status
4.8. Commit
-a
,--all
- commit all changed files--amend
- amend previous commit-C
,--reuse-message <commit>
- reuse message from specified commit--reset-author
- the commit is authored by me now (used with-C/-c/--amend
)-S
,--gpg-sign[=<key-id>]
- GPG sign commit
$ git commit --all --message "ID-10 fix, now working"
$ git commit -a -m "ID-10 fix, now working"
$ git commit -am "ID-10 fix, now working"
4.9. Revert
Undo committed file
$ git reset --soft HEAD^
$ git reset HEAD <file-path>
$ git commit -c ORIG_HEAD
4.10. Push
$ git push
4.11. Further Reading
4.12. Assignments
4.12.1. Clone, Push and Pull
Clone repository via
ssh
Add file
lastname_firstname.txt
Edit
.git/config
and add following[user]
section[user] name = Your Name email = your.email@example.com
Commit using
git commit
Push commit
git push
4.12.2. Advanced Options
Set branch permissions
Make pull request
Squash and merge pull request