-
Notifications
You must be signed in to change notification settings - Fork 3
/
git.commands.txt
547 lines (384 loc) · 14.2 KB
/
git.commands.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
>>>>>>>>>>>>>> Git Commnads (in Git Bash) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
---------------------------------------------------------------------------
Videos Links:
---------------------------------------------------------------------------
Website Links:
//Git command line Documentation for windows 10
https://git-scm.com/book/en/v2/Getting-Started-The-Command-Line
----------------------------------------------------------------------------
----------------------------------------------------------------------------
//These commands for git bash
$ git clone
$ git init
$ git add
$ git mv
$ git reset
$ git rm
$ git bisect
$ git grep
$ git log
$ git show
$ git status
$ git branch
$ git checkout
$ git commit
$ git diff
$ git merge
$ git rebase
$ git tag
$ git fetch
$ git pull
$ git push
$ git --help
$ git --help -a //To show hidden files and folders
$ git --help -g
$ git version
$ git update
$ git revert
$ git quit
$ git diff
$ git patch
$ git add untracked
$ git commit --amend //Changing old commit message
//These command for project directory
$ pwd // Show current directory
$ ch 'c:/xampp/htdocs' // Changing directory path
$ ch '/..' //Changing one directory back
$ ls // Using ls to create a table of contents for burning a CDR disk
$ ls -la //
$ ls -a //Show hidden files
$ ls -als // To see all files and directories in the current directory
$ ls -ls // Show table list
$ ls -s
$ ls -t
$ ls -i
$ ls -v
$ ls -r
$ ls -1
$ ls -2
$ ls -1l
$ ls -1f //List contents in white color
$ cat filename // Lists of the file (showing file contents)
----------------------------------------------------------------------------
usage: git [--version] [--help] [-C <path>] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
---------------->>>>>>>>> Details <<<<<<<<<<<-------------------------------
These are common Git commands used in various situations:
start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one
work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index
examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status
grow, mark and tweak your common history
branch List, create, or delete branches
checkout Switch branches or restore working tree files
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
merge Join two or more development histories together
rebase Reapply commits on top of another base tip
tag Create, list, delete or verify a tag object signed with GPG
collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects
'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
------------------ *********** ------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
---------- R e f e r e n c e -------------------------------------------------------------------------
1.Setup and Config Systex:
git //$ git
config //$ git config
help //$ git --help or $ git help
2.Getting and Creating Projects
init
clone
3.Basic Snapshotting
add
status
diff
commit
reset
rm
mv
4.Branching and Merging
branch
checkout
merge
mergetool
log
stash
tag
worktree
5.Sharing and Updating Projects
fetch
pull
push
remote
submodule
6.Inspection and Comparison
show
log
diff
shortlog
describe
7.Patching
apply
cherry-pick
diff
rebase
revert
8. Debugging
bisect
blame
grep
9. Guides
gitattributes
Everyday Git
Glossary
githooks
gitignore
gitmodules
Revisions
Tutorial
Workflows
10. Email
am
apply
format-patch
send-email
request-pull
11.External Systems
svn
fast-import
12. Administration
clean
gc
fsck
reflog
filter-branch
instaweb
archive
bundle
13. Server Admin
daemon
update-server-info
14. Plumbing Commands
cat-file
check-ignore
checkout-index
commit-tree
count-objects
diff-index
for-each-ref
hash-object
ls-files
merge-base
read-tree
rev-list
rev-parse
show-ref
symbolic-ref
update-index
update-ref
verify-pack
write-tree
-------------------------------------------------------------------------
1. git clone
This command is used for downloading the latest version of a remote project and copying it to the selected location on the local machine. It looks like this:
git clone <repository url>
To clone a specific branch, you can use
git clone <repository url> -b <branch name>
------------------------------------------------------------------
2. git fetch
This Git command will get all the updates from the remote repository, including new branches.
3. git checkout
You can use the checkout command to switch the branch that you are currently working on.
git checkout <branch name>
If you want to create a new branch and switch to it, you can do it by using this command:
git checkout -b <branch name>
-------------------------------------------------------------------
4. git init
This is the command you need to use if you want to start a new empty repository or to reinitialize an existing one in the project root. It will create a .git directory with its subdirectories. It should look like this:
git init <repository name>
-------------------------------------------------------------------
5. git commit
This one is probably the most used Git command. After changes are done locally, you can save them by “committing” them. A commit is like local a snapshot of the current state of the branch, to which you can always come back. To create a new commit, type this command in Git Bash:
git commit -m "<commit message>"
If all goes well, you will see the changes in the commit:
---------------------------------------------------------------------
6. git push
Git push will push the locally committed changes to the remote branch. If the branch is already remotely tracked, simply use it like this (with no parameters):
git push
If the branch is not yet tracked, and only resides on the local machine, you need to run the command like this:
git push --set-upstream <remote branch> <branch name>
-----------------------------------------------------------------------
7. git diff
You can use this command to see the unstaged changes on the current branch. Here’s an example of a branch with an edited feature file:
If you want to see the staged changes, run the diff command like this:
git diff --staged
Or you can compare two branches:
gif diff <branch1> <branch2>
-----------------------------------------------------------------------
8. git pull
Using git pull will fetch all the changes from the remote repository and merge any remote changes in the current local branch.
-----------------------------------------------------------------------
9. git add
This is the command you need to use to stage changed files. You can stage individual files:
git add <file path>
Or all files:
git add .
-----------------------------------------------------------------------
10. git branch
Using git branch will list all the branches of the repository:
Git Branch
Or you can use it to create a new branch, without checking it out:
git branch <new branch>
To delete a branch, run it like this:
git branch -d <branch name> // Or git branch -D <branch name>
-----------------------------------------------------------------------
-----------------------------------------------------------------------
//Set Url on local branch (Rename origin)
$ git remote set-url origin https://github.com/astechedu/Laravel8-breeze-auth.git
git remote add origin http://github.com/UserName/RepositoryName.git
git status
git add .
git commit -m "comments"
git push -u orign main
//create a branch
git branch new-local-repo
git push new-local-repo //Pushes the new branch to new remote repo
git checkout new-local-repo //Checkout or change to branch
git checkout -b subbranch new-local-repo //Create new branch
git branch -d new-local-repo //Delete local branch without loosing any history
git branch -D new-local-repo //
git push origin -delete new-local-repo //Delete a remote branch
OR
git push origin :new-local-repo
git status //To see what branch you are on:
git branch -r //To see remote branches
git branch -m <new_name> //To rename current branch
git branch -a //To see all local and remote branched
--------------------------------------------------------
11. //Reset Last one or two commits:
git reset --hard //Remove //Working
git reset --hard HEAD^ //Remove last one commit //Not done
git reset --hard HEAD^^ //Remove last two commits
git restore --staged <fileName> // back to last step from staging tree
---------------------------------------------------------
-----------Git D e v e l o p m e n t W o r k -----------------------
Merging Branches: Git Development
Ex:
//Merging newBranch To myBranch & myBranch To master branch
1. master branch 2. my branch 3. new branch
Steps:
git branch
echo > newfile1.txt
git add newfile1.txt
git status
git commit -m "new file1.txt added"
git push myorigin newbranch
git checkout mybranch
git branch
git merge newbranch
git status
git push myorigin mybranch
git checkout master
git branch
git merge mybranch
git push myorigin master
//Git Diff Command
git diff <fileNameInWhichSomethingChanged>
git add .
git commit -m "comment"
git push origin master
git diff
git add .
git diff file.txt
git diff --staged tile.txt //Diff in staged file
git status
git reset file.txt //Rest old changes in staged a file
git status
git chechout file.txt
git status //Showing two files in red color
file1.txt
file2.txt
git checkout . //Going to old commit both files
git log //See all comments
--------------------- X ------------ X -------------------------------
Now, you need to set up your username and email address that will be used when issuing a commit:
$ git config --global user.name "Vlad Mihalcea" //Example
$ git config --global user.email mail@vladmihalcea.com //Example
-----------------------------------------------------------------------
Changing Old commit message:
git commit --amend //Opening vi editor to change old commit message
-------------------------------------------------------------------------
Working wiht git:
https://youtu.be/gwWKnnCMQ5c?t=2098
Untracked ----> Unmodified ----> Modified ----> Staged
git status
git add .
git commit -m "message"
git commit -a -m "message"
//Match working directory with last commit (get back last commit)
git checkout contact.html
//Match All working directory(files) with last commit (get back last commit)
git checkout -f
//Showing all commits
git log
//Showing only specified commits (Ex. -1 or -2 or -5 ...)
got log -p -1
//Come out
press q
//Comparing with staging area (after file unmodified)
git diff
//Compare staging area with last commit
git diff --staged
git checkout -f
//Remove files from staging area and working area
git rm
//File remove from staging area only
git rm --cached index.html
git status -s
//Adding feature1 branch this is seperate branch from master or main branch
git branch feature1
git branch
git chckout feature1
//Adding commits OR merge in master from feature1 branch
git log -p -2
git checkout master
git merge feature1
git log -p -2
//Creating new branch and enter it
git branch -b flask (new branch)
//Only one time give this commnd next time git push only in same repo
git push -u oringin main
git push
//Delete untracked files
git clean -Xfd
//Reverting last commit to current file
git revert HEAD
OR
git revert <last commit Id>
//Seeing diff between two commits
git difftool <olderId> <latestId>
OR
//Seeing diff between two commits (position: 0 1 2 3 4 5 ......) : 0 - latest commit(HEAD) & 2 - 3rd commit from last(HEAD~2)
git difftool HEAD~2 HEAD
//If you checkout with perticular id, head not points to last commit
git checkout <perticularCommitId>
git log
:end: