Repository navigation
Expand file tree
/
Copy pathGit
More file actions
230 lines (119 loc) · 4.55 KB
/
Copy pathGit
File metadata and controls
230 lines (119 loc) · 4.55 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
- Git is a Distributed Version Control System.
. In this situation everybody has a local repository.
- SVN is Central Version control System.
. a central VCS is located in one place.
Helpful GIT Commands:
- Set Config Values:
git config --global user.name "Vinay"
git config --global user.email "someemail"
These are the global values to check who made the changes or code changes.
To check the config values: git config --list
- git config is the first verb or action that we use.
Initialize Local Git Repository:
git init
Adds all files in local Source Directory:
git add . (or)
git add --all
Removes Specific Files:
git rm --cached filename.sh
Shows all files to be Commited:
git status
Creates the connection to where you are pushing - repository:
git remote add localbranchname
Associate a local and remote branch:
git push --set-upstream origin remotebranchname
Create a local branch and switch to it:
git checkout -b localbranchname / remotebranchname
Making changes:
git commit -a -m 'made a change' (or)
git commit -am "made a change" (or)
git commit -m "made a change"
Branch renaming:
git checkout oldname
git branch -m oldname newname
Merging changes:
git checkout master / branch (you want to merge to)
eg: git checkout feature branch
Show remote repositoris:
git remote
git remote -v
Also refer to .git/config
get data from remote:
git fetch remote -name
Pushing to remotes:
git push origin master
git push localbranchname master
git push
Pushing to remote branches:
git push origin localbranchname
git push (connector) localbranchname
git push localbranchname remotebranchname
Checkout Remote Branches:
git checkout -b hotfix origin/localbranchname
Tracking Branches:
git checkout --track origin/featurebranch
git checkout featurebranch
Deleting Remote Branches:
git push origin --delete remotebranchname
Deleting Local Branch:
git branch -d localbranchname
Fetch al remote Branches:
git branch -v -a
Hard reset to Masrter:
git fetch origin && git reset --hard origin/master && git clean -f -d
GIT WorkFlow:
- Fetch and Merge changes from the remote
- create a branch to work on a new project feture
- Develop the feature on your branch and commit your work
- Fetch and merge from the remote again (in case new commits were made while you were working)
- Push your branch up to the remote for review.
Undo a merge:
- ON CLI: git merge --abort
git reset --hard
Git Push: git push origin <filename>
- git clone -> creates a local copy of a remote
- git remote -v -> lists a git project remotes
- git fetch -> fetches work from remote into the local copy (repo)
- git merge origin/master merges origin/master into your local branch
- git push origin <branch name> pushes local branch into the origin
- Merge Conflicts
- git diff
- git whatchanged
Getting Started:
- Two common senarios :-
1. an existing project on your local machine, that you want to start tracking using git.
2. When ever there is an existing project that you want to start developing on.
############ Initialize Repository from existing code ##############
git init (will initialize empty git repository)
eg: locate the code base you want to start tracking using git -ls
- you will see a .git directory
- This .git directory contains everything that relate to our repository
Note: if we ever want to stop tracking our project with git, all we have to do is ###### rm -rf .git #######
- we are using git but we never commited anything.
" Before we commit "
git status
- When we run git status you can see the untracked files.
- on a personal computer you have files and you don't to add those files to the repository, so ignore those files for that you need to create ignore file.
touch .gitignore
- which will create that .gitignore file.
- gitignore file is just a simple text file, where we can add files that we want git ignore and we can also use wildcards.
- with git there are 3 stages to remember:
Working Directory
Staging Directory
Commited files
- untracked and modified files will be in our working directory.
###### Important Commands to remember #######
git add
git status
git commit -m "message"
git push origin master
git chekout (branch name)
-----------------------------
git :q - to exit
git revert HEAD
git :x
git log
git revert --no-edit (note: --no-edit bypasses the message editor)
fatal: refusing to merge unrelated histories : Perform below git - command
git pull origin <branch> --allow-unrelated-histories
git rm -r --cached node_modules