Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
252 lines (230 loc) · 13.9 KB
/
Copy pathindex.html
File metadata and controls
252 lines (230 loc) · 13.9 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="./fav.png" />
<link rel="stylesheet" href="style.css">
<title>MyGit Docs</title>
</head>
<body>
<div class="container">
<section>
<h2> Definition</h2>
<p> ⇎ Repositories is just a container for a project you want to track with Git</p>
<p> ⇎ Commit : Save point</p>
<p> ⇎ Modified : file created or modified</p>
<p> ⇎ github is a service that lets us set up hosted repositories , remote repositories</p>
<p> ⇎ central online repository which multiple team-members could access </p>
<div class="main">
<div class="project">
<p> ⇎ myProject folder</p>
<p> ⇎ -- .get</p>
<p> ⇎ -- index.html</p>
<p> ⇎ -- style.css</p>
</div>
<div class="table">
<table>
<tr>
<th>Modified</th>
<th>Staging</th>
<th>Committed</th>
</tr>
<tr>
<td>index.html</td>
<td>add any changed files to staging<br> area
that you want to commit</td>
<td></td>
</tr>
</table>
</div>
</div>
<p> ⇎ git --version : check the installed version of git </p>
<p> ⇎ config git username and email </p>
<p> ⇎ git config --global user.name "Your Name" </p>
<p> ⇎ git config --global user.email "you@example.com" </p>
<p> ⇎ git config --global user.name : get the name</p>
</section>
<section>
<h2>Commandes</h2>
<p> ⇎ git init <em>// turn the folder into a git repo ( folder tracked with git )</em>
</p>
<p> ⇎ git status <em> // if = <span class="red">red</span> files changed and ready to be staged
// if = <span class="green">green</span> files staged and ready to be committed</em></p>
<p> ⇎ git add index.html <span>// add ' index.html ' file to the staging area</span> </p>
<p> ⇎ git reset <em>// remove all files from staging area</em></p>
<p> ⇎ git rm --cached index.html <em>// remove ' index.html ' file from staging area</em> </p>
<p> ⇎ git add . <em>// add all files to the staging area</em></p>
logical points after developing certain features of a website or application - we can split our work by
different commits</p>
<p> ⇎ git commit -m "added index and style" <em>// commit ( save ) files , 'm' stands for message</em>
</p>
<p> ⇎ staging area allows us to review the changes before
committing them</p>
<p> ⇎ git log --oneline <em>// each commit in one line</em> </p>
<p> ⇎ git log <em>// history of all commit</em> </p>
<p class="title">Rename the local master branch to main</p>
<p> ⇎ git branch -m master main</p>
<p> <em>// if it is not working try to commit something to the master branch and try again</em></p>
<p class="title">Add Submodule</p>
<p> ⇎ git submodule add <repo-link> <em>// repo inside repo</em></p>
</section>
<section>
<h2>Undo</h2>
<div>
<h3> undoing things (order of danger)</h3>
<div class="commit">
<p>Checkout commit (safe)</p>
<p>Revert commit (little safe)</p>
<p>Reset commit (unsafe)</p>
</div>
</div>
<p> ⇎ git log // get all the commits with their id</p>
<p> ⇎ git checkout af6b84c // af6b84c : commit id (detach this commit from the master
branch)</p>
<p>and see how the code is looks like before this commit this does not affect the commit history just
readonly</p>
<p> ⇎ git checkout master // reatach to the master bracnch ( like undo : Ctrl+z) back to
normal</p>
<p>after checking the code go back to the normal state</p>
<hr>
<p> ⇎ git revert af6b84c // af6b84c : commit id, :wq ( undo one particular commit
(this commande do a commit
for us just revert the given commit 'add border' become 'Revert "add border"' ))
</p>
<p>revert the giving commit (af6b84c)</p>
<hr>
<p> ⇎ git reset af6b84c // af6b84c : commit id ( remove all the commit after this commit id
but not changing the
files)</p>
<p> ⇎ git reset af6b84c --hard // af6b84c : commit id, --hard // remove the changes after
this
commit id - reset the code to a particular commit</p>
</section>
<section>
<h2>Branches</h2>
<p> ⇎ when creating a new repository it also creates a master branch </p>
<p> ⇎ master branch represent the stable version of the code which will be released or
published</p>
<p> ⇎ if we need to add a new feature to our code we add it to a new branch and if we like
it we can merge this branch with the master branch</p>
<p> ⇎ if we have two developers working on the same
project they can create a new branch for each
feature and when they done we can merge them to the
master branch </p>
<p> ⇎ we can also delete the branch</p>
<p> ⇎ git branch screenFeature // create new branch</p>
<p> ⇎ git branch -a // display all branches</p>
<p> ⇎ git checkout screenFeature // work in the screenFeature branch</p>
<p> ⇎ branche is like copy past the same project and work on it</p>
<p> ⇎ git branch -D screenFeature // delete a branch (not merged ? -D : -d)</p>
<p> ⇎ git checkout -b screenFeature // create and work in a new branch 'screenFeature' (
just
a shortcut)
</p>
<p class="title">Remove file / folder from git</p>
<p>if the file is still in the staging area : <br> ⇎ git reset < file_name > <em> // to
unstage the file</em></p>
<p>⇎ git rm --cached < file_name > <em> // remove the file</em>
<p>⇎ git rm -r --cached < folder_name > <em> // remove the folder</em>
</p>
</section>
<section>
<h2>Merging Branches Conflicts</h2>
<p>When working with Git, you'll often be switching between branches to work on different features or fixes. Eventually, you'll want to bring your changes back together. This is done by merging branches.</p>
<p> Once you're happy with the changes in a feature branch (e.g. feature-a), it's time to merge those changes back into the main branch (usually called main or master).</p>
<p> ⇎ first you have to be in the branch you want to merge into (master)</p>
<p> ⇎ git merge feature-a <em>// merge the code in feature-a with master</em> </p>
<p> ⇎ git merge feature-b <em>// merge the code in feature-b with master</em></p>
<p> ⇎ " when you create a new branch and change something in the master and change the same
thing in the new
branch this may create a conflict when you want to merge them "</p>
<p> ⇎ after merging, you can push the master branch to GitHub </p>
</section>
<section>
<h2>Github</h2>
<p> ⇎ if you have a local repository <em>// ( clone a repo create a local repository )</em></p>
<p> ⇎ make sure all is commited : git status</p>
<p> ⇎ git push https:// github.com/MohcineDev/gitDes.git master <em>// push files to Github repo
with the master branch</em>
</p>
<p> ⇎ clone by press the clone btn</p>
<p class="title">add alias to a url</p>
<p> ⇎ git remote add aliasName https:// github.com/projectname/name.git </p>
<p> ⇎ git remote add origin https:// github.com/MohcineDev/gitDes.git <em>// give the url an alias = origin</em></p>
<p> ⇎ push after make changes</p>
<p> ⇎ add code to staging area then commit</p>
<p> ⇎ git push origin master</p>
<p class="title">update remote</p>
<p> ⇎ git remote set-url origin <new-url> </p>
<p> ⇎ if you dont have a local repository</p>
<p> ⇎ create one in github and clone it </p>
<p> ⇎ git clone https:// github.com/MohcineDev/gitDes.git <em>// clone repo and add alias origin</em>
</p>
<p> ⇎ make changes</p>
<p> ⇎ git add . <em>// add to staging area</em> </p>
<p> ⇎ git commit -m "added index. file" <em>//commit changes</em> </p>
<p> ⇎ git remote -v <em> info about the alias for push and fetch</em></p>
<p> ⇎ git push origin master <em> push master branch files to github</em></p>
</section>
<section>
<h2>Collaborate</h2>
<p> ⇎ first make sure you are in master (update our master) and everything is commited</p>
<p> ⇎ git pull origin master : pull code from remote master branch and update our local
master branch with it
</p>
<p> ⇎ git checkout -b index-html : create your working branch dont miss with the master</p>
<p> ⇎ add to staging area and commit it </p>
<p> ⇎ dont merge it with master</p>
<p> ⇎ git push origin index-html : push your branch to give your team the chance to
reviewing
it before merging
it
with master</p>
<p> ⇎ git pull origin master :</p>
<p> ⇎ fork means create a copy of the repo from the main account to our account</p>
<p> ⇎ clone it make changes commit it push it to github</p>
<p> ⇎ click btn 'new pull request' ..</p>
<hr>
<hr>
<p> ⇎ 1 : fork the open source repo to your account </p>
<p> ⇎ 2 : clone the repo </p>
<p> ⇎ 3 : create your branch </p>
<p> ⇎ 4 : commit your changes </p>
<p> ⇎ 5 : push the changes to your account </p>
<p> ⇎ Contribute this changes to the original repository </p>
<p> ⇎ 1 : click btn 'new pull request' .. </p>
<p> ⇎ 2 : see if it can be merged </p>
<p> ⇎ 3 : press create pull request </p>
<p> ⇎ and the rest is on the repo owner </p>
</section>
<section>
<h2>Git Best Practices</h2>
<p> ⇎ Always pull before you start working</p>
<p> ⇎ Commit often with clear, descriptive messages</p>
<p> ⇎ Use feature branches for new developments</p>
<p> ⇎ Never commit directly to master/main branch</p>
<p> ⇎ Use .gitignore to prevent unnecessary files</p>
<p> ⇎ Review changes before committing</p>
<p> ⇎ Keep commits atomic (one purpose per commit)</p>
<p> ⇎ Use pull requests for code reviews</p>
<p> ⇎ Merge with squash for clean history</p>
</section>
<section>
<h2>Using Token</h2>
<p>Token authentication requirements for Git operations </p>
<p>using access token instead of password</p>
<p>if the repo is already cloned remove the remote first</p>
<p>⇎ git remote remove < remote name ></p>
<p>add the new remote with the token </p>
<p>⇎ git remote add <remote name> https:// <accress
token>@github.com/<username>/<repo
name>.git</p>
</section>
</div>
<div class="onGitHub">
<a href="https:// github.com/MohcineDev" class="move" target="_blank">
@Mohcinedev</a>
</div>
</body>
</html>