forked from Sonal0409/25July-Batch-DevOps-Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGit-Notes
304 lines (116 loc) · 4.53 KB
/
Git-Notes
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
to become a super user, which can downloa dand install packages
1. sudo su -
To install git:
$ yum install git -y
mkdir myprojects
cd myprojects
touch index1.html
ls
Intsialise git
git init
ls -al
.git folder will be there
Scenario 1:
***********
Check if git is tracking you files or not in the workspace
git status
git add filename ==> single file
git add file1 file2 ==> will add 2 files
$ git add . ==> all the files will be stagged
$ git commit -m "message " ==> all the chnages & files will be commited
Scenario 2: git config
*******************
$ git config --global user.name sonal0409
$ git config --global user.email [email protected]
To see the list of configurations:
git config --list
Scenario 3: log in git
******************
git log
git log --oneline
git show <commitid> ==> show all the details of the changes that have been commited
100644
644 ==> current user ==> read and write permsision = 6
==> group users ==> read permission = 4
==> user ==> read permssion
chmod 666 filename
Scenario 4: How modified files with changes can be commited to Local repository
*********************
Take a file that is already committed OR which is already tracked by git
In this case no need to explicitly execute add command, you can directly commit all the changes using the command
$ git commit -a -m "modified file"
- a : take all the modified files or stagged files and commit them all
vim index1.html
press i
enter data
save the file:
press ESC key on keyboard
then enter the keys :wq!
press enter key
Scenario 5: Delete a file and commit the changes to Local repo
Step 1: take an exisitng file and delete it
git rm newfile1 ==> delete file from LR & Working directory
Step 2: Check status of git, you will deleted file or change is stagged
you need to commit
git commit -m "deleted file"
See the log
$ git log --oneline
Scenario 6: revert the changes to its previous state
Select the required commit id
$ git log --oneline
see what happened in that commit
$ git show 5f62be1
Lets revert the commitid
whatever was commited, will go back to its previous state
$ git revert <commitid>
When the above command is executed,
git will open an editor for you,
where you have to put a message as to why are your reverting
AND
git will perform revert action and generate a commit id for it
Expected : file should be back to LR & WD
Scenario 7: Push the changes from LR to Github
Steps to create personal Access token
Personal access tokens function like ordinary OAuth access tokens. They can be used instead of a password for Git over HTTPS,
or can be used to authenticate to the API over Basic Authentication.
Go to settings of the github account
Scroll down and click on developer settings on the left
on the left side click on personal access token
Click on generate token
> in Note give a unique name of token
> expiration 30 days
> scope ==> select repo
Scenario 8: Pull files from remote repository
Step1: create some new file in the remote repostiroy, which are not in your local repo
Step 2: go to local repo and pull these new changes form remote
here PULL ==> Fetch the changes + Merge them with local repo and working directory
git config pull.rebase false
Scenario 9 : clone the remote repo to local
git clone reponame
Scenario 10: Forking in remote repo
click on for button on github repo
Scenario 11 : Branching & Merging
git branch feature
git checkout feature
make chnages and commit on branch
git checkout master
git merge feature master
git branch -d feature
Scenario 12: Conflicts & resolve conflicts
Create a file on the remote repo with a new name : demo1
Step2:
Sonal also working on the same file Demo1 in her local machine
Step 3:
Sonal want to push her demo changes from local into remote file, so that somebody can review those changes
Observation: Push will not be successfull
it will reject the push
Step 4: because my push was rejected and I am asked to pull the chnages first from remote file,
so lets execute pull command
$ git pull origin master
You will get into conflict, because git donot know where to merge the chnages fetched from remote in the local file
CONFLICT (add/add): Merge conflict in Demo1
Automatic merge failed; fix conflicts and then commit the result.
Step 5: Resolve the conflict
Review the changes in the file locally and commit the changes so as to resolve conflict
Step 6:
Once you resolve the conflicts, push the changes to remote