-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGit Tutorial Notes.txt
121 lines (75 loc) · 5.13 KB
/
Git Tutorial Notes.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
Video --> https://www.youtube.com/watch?v=q8EevlEpQ2A
------------------------------------------------------
1. [git status]
To check the status of a repository already git added or not.
2. [git init] ---> Current folder is now 'Working Directory'
If not than this cmd add git on current directory
3. [git add]
Create Staging area means selected/all files are on stage.
1. Selected Files: [git add file1 file2]
2. All Files: [git add .]
-->To 'unstage' files: [git rm --cached <fileName>]
-->To 'update' changes in file: [git add <fileName>]
-->To 'discard' changes in working directory: [git restore <fileName>]
4. [git commit]
Send all files & changes from staging area to repo.
-->To see all the commits done so far: [git log]
-->To see less info log: [git log --oneline]
* .gitignore -> use to ignore some file we don't want to track or upload to vcs.
---> just mentioned the file name in it and git will not track that file.
* .gitkeep -> git not track empty folders, but to make it track we have to create .gitkeep file on that empty folder to make git track it as well.
------------------------------------------------------
i. [git branch]
--> Show the current 'branch' where HEAD is pointing.
ii. [git branch new-branch]
--> With this we can create new branch with given name.
iii. [git switch new-branch]
--> This will switch the branch and make it current 'branch' where HEAD is pointing.
iv. [git checkout branch-name]
--> Switch the branch.
v. [git switch -c new-branch]
--> This makes new branch & switched to that branch, If branch already there with same name then it will just switched to that.
vi. [git merge branch-name]
--> This will merge the mentioned branch-name to the current branch where we calling it to merge.
vii. [git merge --abort]
--> This will abort the merge in case of merge-conflict issue.
viii. [git branch -m old-branch-name new-branch-name]
--> Rename branch name.
ix. [git branch -d branch-name]
--> Delete specified branch.
------------------------------------------------------
i. git diff -> Its a informative command, which gives only information of difference between 2 things.
--> [git diff --staged] : This cmd shows the diff. between your last commit & your current staging area info. which are not committed at.
--> [git diff branch-name1 branch-name2] ya [branch-name1..branch-name2] both are correct : Gives diff. between 2 branches.
ii. git stash -> It is way to save your changes on a temporary basis. Just want to make changes in a file but don't want to commit them yet.
--> [git stash] : stash/saved work in temporary location.
--> [git stash save "Work in progress in this feature"] : You can stash with msg also.
--> [git stash list] : show all the list of saved stashed, like (stack-based).
--> [git stash apply] : top-one stash come to staging area to commit.
--> [git stash apply stash@{0}] : or call with specific stash num.
--> [git stash pop] : This will apply the stash and also drop from stash list.
--> [git stash drop] : To drop the stash.
--> [git stash apply stash@{0} branch-name] : This will apply the stash to a specific branch.
--> [git stash clear] : clear the stash list.
iii. git rebase 🚫 -> It's a powerful git feature use to change the (BASE of a BRANCH). Its allow you to move a (branch to a new starting point), it used to make cleaner, linear project history.
⚠ Caution: It change's the (PROJECT HISTORY).
--> Rebase is always done on a sub-branch not on a main/master branch.
--> [git rebase branch-name] : rebase the given branch-name to the current branch, means (without giving another commit on a git history) it will copy all the changes present in a given branch-name to the current branch.
iv. [git reflog] -> It's same as log, just give detailed look of commit history.
v. ⚠ [git reset --hard commit-hash] : It will restore the back-state of a file based on given commit-hash. Once backed no way to restore.
------------------------------------------------------
5. git push -> Push all the files on GitHub or any other chosen service.
⚠ Caution: Every System use single SSH-KEY so before generating new key first look for existing one, in your GitHub profile.
For new SSH-Key setup: Refer GitHub doc's (https://docs.github.com/en/authentication/connecting-to-github-with-ssh)
1. Add origin: [git remote add origin repoURL] --> copy link from [code] sec https link.
---> To Fix Git ‘remote: Repository not found’ Error?
- Step-1: Verify the Repository URL For example: [https://github.com/username/repository.git]
- Step-2: If the URL is incorrect, update it using: [git remote set-url origin repoURL]
2. Check connection: [git remote -v] shows both fetch & push msg.
i. First time push: [git push -u origin main]
ii. Second time onwards push directly: [git push]
⚠ Caution: If Read.me file is added on time of creating repository then it will throw conflict-error at starting.
--> To resolve that use: [git pull --rebase origin type-branch-name(main or master)] -> rebase to solve issue.
------------------------------------------------------
Detailed gfg article for issue of ‘remote: Repository not found’ Error:
https://www.geeksforgeeks.org/how-to-fix-git-remote-repository-not-found-error/