Rabu, 08 Maret 2017

Git Command Snippet

Karena saya pengguna Git yang aktif, tentunya saya harus hafal perintah untuk mengoperasikannya. Sayangnya, yang saya hafal hanya clone, add, commit, dan push. Selain itu saya tidak hafal, maka dari itu saya buat catatan ini untuk memudahkan saya mengingat berbagai perintah dalam Git yang umum di gunakan.

Setup and Config

Global
git config --global user.email "your_email@example.com"
git config --global user.name "Em Suryadi"
Current repository
git config user.email "your_email@example.com"
git config user.name "Em Suryadi"

Getting and Creating Projects

Init repository
git init
Clone repository from remote server
git clone https://server.com/project-name/project.git

Basic Snapshotting

Pull repository from remote server
git pull origin
Add
git add .
#atau
git add --all
Status
git status
Diff
git diff
Commit
git commit -m "commit title"
Push to remote server
git push origin
Clear index cache and retrack
git rm -r --cached .

Submodules

Add submodule from remote server
git submodule [--quiet] add [<options>] [--] <repository> [<path>]
Init submodule from remote server
git submodule [--quiet] add [<options>] [--] <repository> [<path>]
Update submodule from remote server
git submodule [--quiet] update [<options>] [--] [<path>…​]

SNIPPET:

How to exit (“fix”) detached HEAD state when you already changed something in this mode and want to save your changes. (That part is optional though.)

Commit changes you want to keep. If you want to take over any of the changes you made in detached HEAD state, commit them. Like:
git commit -a -m "your commit message"

Discard changes you do not want to keep. The hard reset will discard any uncommitted changes that you made in detached HEAD state:
git reset --hard
(Without this, step 3 would fail, complaining about modified uncommitted files in the detached HEAD.)

Check out your branch. Exit detached HEAD state by checking out the branch you worked on before, for example:
git checkout master

Take over your commits. You can now take over the commits you made in detached HEAD state by cherry-picking, as shown in my answer to another question.
git reflog
git cherry-pick (hash1) (hash2) ...

Sekian, terimakasih.

Sumber:

  1. https://git-scm.com/docs

Show Comments