|
1 |
| -# README |
| 1 | +# Panduan Penggunaan Git |
| 2 | + |
| 3 | +* [Mengunduh repository ke dalam komputer](http://https://github.com/datascienceid/README#mengunduh-repository) |
| 4 | +* [Memperbarui repository yang telah diunduh](https://github.com/datascienceid/README#memperbarui-repository) |
| 5 | +* [Mengunggah perubahan ke dalam repository](https://github.com/datascienceid/README#mengunggah-perubahan) |
| 6 | +* [Menghapus file](https://github.com/datascienceid/README#menghapus-file) |
| 7 | +* [Branching](https://github.com/datascienceid/README#branching) |
| 8 | +* [Perintah tambahan](https://github.com/datascienceid/README#perintah-tambahan) |
| 9 | + |
| 10 | +## Mengunduh Repository |
| 11 | + |
| 12 | +Unduh repository ke dalam komputer menggunakan perintah `git clone`. Url |
| 13 | +repository dapat dilihat di dalam repository yang diinginkan. |
| 14 | + |
| 15 | +``` |
| 16 | +git clone <url repository> <folder tujuan> |
| 17 | +``` |
| 18 | + |
| 19 | +#### Contoh |
| 20 | + |
| 21 | +``` |
| 22 | +user@host:~$ git clone https://github.com/datascienceid/instagram.git instagram |
| 23 | +Cloning into 'instagram'... |
| 24 | +remote: Counting objects: 4, done. |
| 25 | +remote: Compressing objects: 100% (4/4), done. |
| 26 | +remote: Total 4 (delta 0), reused 4 (delta 0), pack-reused 0 |
| 27 | +Unpacking objects: 100% (4/4), done. |
| 28 | +``` |
| 29 | + |
| 30 | +## Memperbarui Repository |
| 31 | + |
| 32 | +Perbarui repository yang telah diunduh ke dalam komputer menggunakan perintah |
| 33 | +`git pull`. |
| 34 | + |
| 35 | +``` |
| 36 | +git pull origin <nama branch> |
| 37 | +``` |
| 38 | + |
| 39 | +#### Contoh |
| 40 | + |
| 41 | +``` |
| 42 | +git pull https://github.com/datascienceid/instagram.git master |
| 43 | +From https://github.com/datascienceid/instagram |
| 44 | + * branch master -> FETCH_HEAD |
| 45 | +Already up-to-date. |
| 46 | +``` |
| 47 | + |
| 48 | +## Mengunggah Perubahan |
| 49 | + |
| 50 | +Jangan lupa untuk melakukan pull terlebih dahulu sebelum melakukan push. |
| 51 | + |
| 52 | +**Tambah file baru atau ubah file** |
| 53 | + |
| 54 | +``` |
| 55 | +git add <nama file> |
| 56 | +``` |
| 57 | + |
| 58 | +**Konfirmasi penambahan atau perubahan file** |
| 59 | + |
| 60 | +``` |
| 61 | +git commit -m "<pesan commit>" |
| 62 | +``` |
| 63 | + |
| 64 | +**Kirim perubahan ke dalam repository** |
| 65 | + |
| 66 | +``` |
| 67 | +git push origin <nama branch> |
| 68 | +``` |
| 69 | + |
| 70 | +#### Contoh |
| 71 | + |
| 72 | +``` |
| 73 | +user@host:~$ git add README.md |
| 74 | +
|
| 75 | +user@host:~$ git commit -m "Menambahkan readme" |
| 76 | +[master 224c510] Menambahkan readme |
| 77 | + 1 file changed, 1 insertion(+) |
| 78 | + create mode 100644 README.md |
| 79 | +
|
| 80 | +user@host~$ git push origin master |
| 81 | +Counting objects: 3, done. |
| 82 | +Delta compression using up to 16 threads. |
| 83 | +Compressing objects: 100% (2/2), done. |
| 84 | +Writing objects: 100% (2/2), 271 bytes | 0 bytes/s, done. |
| 85 | +Total 2 (delta 1), reused 0 (delta 0) |
| 86 | +remote: Resolving deltas: 100% (1/1), completed with 1 local objects. |
| 87 | +To https://github.com/datascienceid/instagram.git |
| 88 | + fec3a1f..224c510 master -> master |
| 89 | +``` |
| 90 | + |
| 91 | +## Menghapus File |
| 92 | + |
| 93 | +Hapus file dari repository menggunakan perintah `git rm`, diikuti dengan `git commit`, dan `git push`. |
| 94 | + |
| 95 | +``` |
| 96 | +git rm <nama file> |
| 97 | +``` |
| 98 | + |
| 99 | +#### Contoh |
| 100 | + |
| 101 | +``` |
| 102 | +user@host~$ git rm README.md |
| 103 | +rm 'README.md' |
| 104 | +
|
| 105 | +user@host~$ git commit -m |
| 106 | +[master 658a76e] Menghapus README |
| 107 | + 1 file changed, 1 deletion(-) |
| 108 | + delete mode 100644 README.md |
| 109 | +
|
| 110 | +user@host~$ |
| 111 | +Counting objects: 3, done. |
| 112 | +Delta compression using up to 16 threads. |
| 113 | +Compressing objects: 100% (2/2), done. |
| 114 | +Writing objects: 100% (2/2), 236 bytes | 0 bytes/s, done. |
| 115 | +Total 2 (delta 1), reused 0 (delta 0) |
| 116 | +remote: Resolving deltas: 100% (1/1), completed with 1 local objects. |
| 117 | +To https://github.com/datascienceid.git |
| 118 | + 224c510..658a76e master -> master |
| 119 | +``` |
| 120 | + |
| 121 | +## Branching |
| 122 | + |
| 123 | +Branch digunakan untuk mengembangkan fitur baru atau mengubah source code tanpa |
| 124 | +memberikan dampak kepada branch lain. Branch master adalah branch default dari |
| 125 | +sebuah repository. Gunakan branch lain untuk melakukan pengembangan dan |
| 126 | +gabungkan kembali ke dalam branch master. |
| 127 | + |
| 128 | +### Melihat branch yang terdapat di dalam repository lokal |
| 129 | + |
| 130 | +``` |
| 131 | +git branch |
| 132 | +``` |
| 133 | + |
| 134 | +``` |
| 135 | +user@host~$ git branch |
| 136 | +* master |
| 137 | +``` |
| 138 | + |
| 139 | +Tanda asterisk (\*) menandakan branch yang sedang aktif. |
| 140 | + |
| 141 | +### Melihat branch yang terdapat di dalam repository lokal |
| 142 | + |
| 143 | +``` |
| 144 | +git branch -r |
| 145 | +``` |
| 146 | + |
| 147 | +``` |
| 148 | +user@host~$ git branch -r |
| 149 | + origin/HEAD -> origin/master |
| 150 | + origin/master |
| 151 | +``` |
| 152 | + |
| 153 | +### Membuat branch baru di dalam repository lokal dan kirim ke repository remote |
| 154 | + |
| 155 | +**Buat branch baru** |
| 156 | + |
| 157 | +``` |
| 158 | +git branch <nama branch baru> |
| 159 | +``` |
| 160 | + |
| 161 | +**Aktifkan branch baru** |
| 162 | + |
| 163 | +``` |
| 164 | +git checkout <nama branch baru> |
| 165 | +``` |
| 166 | + |
| 167 | +**Konfirmasi perubahan** |
| 168 | + |
| 169 | +``` |
| 170 | +git commit -m "<pesan konfirmasi>" |
| 171 | +``` |
| 172 | + |
| 173 | +**Unggah branch baru ke dalam repository remote** |
| 174 | + |
| 175 | +``` |
| 176 | +git push origin <nama branch baru> |
| 177 | +``` |
| 178 | + |
| 179 | +#### Contoh |
| 180 | + |
| 181 | +``` |
| 182 | +user@host~$ git branch development |
| 183 | +
|
| 184 | +user@host~$ git checkout development |
| 185 | +Switched to branch 'development' |
| 186 | +
|
| 187 | +user@host~$ git commit -m "Menambah branch development" |
| 188 | +On branch development |
| 189 | +nothing to commit, working tree clean |
| 190 | +
|
| 191 | +user@host~$ git push origin development |
| 192 | +Total 0 (delta 0), reused 0 (delta 0) |
| 193 | +remote: |
| 194 | +remote: Create pull request for new: |
| 195 | +remote: https://github.com/datascienceid/instagram/pull-requests/new?source=new&t=1 |
| 196 | +remote: |
| 197 | +To https://github.com/datascienceid/instagram.git |
| 198 | + * [new branch] development -> development |
| 199 | +``` |
| 200 | + |
| 201 | +### Menambahkan branch dari repository remote ke dalam repository lokal |
| 202 | + |
| 203 | +``` |
| 204 | +git branch <nama branch remote> |
| 205 | +git pull origin <nama branch remote> |
| 206 | +git checkout <nama branch remote> |
| 207 | +``` |
| 208 | + |
| 209 | +#### Contoh |
| 210 | + |
| 211 | +``` |
| 212 | +user@host~$ git branch development |
| 213 | +
|
| 214 | +user@host~$ git pull origin development |
| 215 | + * branch new -> FETCH_HEAD |
| 216 | + * [new branch] new -> origin/development |
| 217 | +Already up-to-date. |
| 218 | +
|
| 219 | +user@host~$ git checkout development |
| 220 | +Switched to branch 'development' |
| 221 | +``` |
| 222 | + |
| 223 | +### Menggabungkan branch lain ke dalam branch aktif |
| 224 | + |
| 225 | +**Aktifkan branch yang diinginkan** |
| 226 | + |
| 227 | +``` |
| 228 | +git checkout <nama branch aktif> |
| 229 | +``` |
| 230 | + |
| 231 | +**Perbarui branch local** |
| 232 | + |
| 233 | +``` |
| 234 | +git pull origin <nama branch aktif> |
| 235 | +``` |
| 236 | + |
| 237 | +**Penggabungan** |
| 238 | + |
| 239 | +``` |
| 240 | +git merge <nama branch yang akan digabungkan> |
| 241 | +``` |
| 242 | + |
| 243 | +**Cek dan selesaikan konflik akibat penggabungan branch** |
| 244 | + |
| 245 | +``` |
| 246 | +git status |
| 247 | +``` |
| 248 | + |
| 249 | +**Konfirmasi dan unggah penggabungan branch** |
| 250 | + |
| 251 | +``` |
| 252 | +git commit -m "<pesan konfirmasi>" -a |
| 253 | +git push origin <nama branch aktif> |
| 254 | +``` |
| 255 | + |
| 256 | +#### Menghapus branch |
| 257 | + |
| 258 | +**Pada repository remote** |
| 259 | + |
| 260 | +``` |
| 261 | +git push origin :<nama branch> |
| 262 | +``` |
| 263 | + |
| 264 | +**Pada repository lokal** |
| 265 | + |
| 266 | +``` |
| 267 | +git branch <nama branch> -d |
| 268 | +``` |
| 269 | + |
| 270 | +## Perintah tambahan |
| 271 | + |
| 272 | +Dapatkan status dari repository |
| 273 | + |
| 274 | +``` |
| 275 | +git status |
| 276 | +``` |
| 277 | + |
| 278 | +Dapatkan log dari sebuah repository |
| 279 | + |
| 280 | +``` |
| 281 | +git log |
| 282 | +``` |
0 commit comments