-
Notifications
You must be signed in to change notification settings - Fork 1
/
Git.txt
235 lines (167 loc) · 7.33 KB
/
Git.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
Content-Type: text/x-zim-wiki
Wiki-Format: zim 0.4
Creation-Date: 2016-11-23T10:53:06+01:00
====== Git ======
Created onsdag 23 november 2016
**A usual Git workflow goes something like : **
**# Create a new project (will create an initial master branch)**
**# Do some initial file/project creation (project)**
**# Create a branch (git) and make changes/additions (project)**
**#** **Then commit those changes.**
**# Merge the commits changes to the master branch**
**# (Optional) Push to remote server (github)**
== Installation ==
# **Install the **//git//** package along with **//aspell//** for spell-checking**
$ pacman -S git aspell
== Configuration ==
**# Name and E-mail**
$ git config --global user.name "Henrik Jeppesen"
$ git config --global user.email "[email protected]"
**# Default editor (vim)**
$ git config --global core.editor "vim"
===== File Handling =====
**# Handling files with Git manages them in Git index HEAD. The files themselves are not touched.**
== Create new repository ==
$ cd //<your_project>///
$ git init
== Adding files to the index three ==
**# Once you've created/modified some files, they need to be added to Gits index tree. **
**# This will make git able to record changes in files and commit those changes.**
$ git add //file1 file2//
**# To add all files **
$ git add . **# note the dot (.)**
**# This will record the state of the files. **
**#** **If files are later modified, run **//git add//** again to add a new version to the index.**
== Ignoring files ==
**# It is possible to create a list for files, which should not be included when running **//git add .//** (add all)**
**# Create a file in your git directory called **//.gitignore //**and choose from the following (add-able)**
{{{code: lang="texinfo" linenumbers="True"
# File I'll likely delete
test-script
# Ignore all .html files, except 'important.html'
*.html
!important.html
# Ignore all files recursively in 'DoNotInclude'
DoNotInclude/**
}}}
== Removing files ==
**# To remove one file**
$ git rm --cached //<filename>//
**# To remove all files**
$ git rm --cached -r . **# note the dot (.)**
== Other file management options ==
**# Rename a file**
$ git mv //<oldname> <newname>//
**# List files **
$ git ls-files
===== Commit Changes =====
**# You should commit changes to a branch (See a little further down)**
**# Once changes/additions has been made, commit those changes. Commit often.**
**# **//-a//** will add changes from all known files.**
**# If -**m "message"** is excluded, the default text-editor will open, allowing you to add a long message.**
$ git commit -m "Short Message."
**# Change/edit the message for the last commit**
$ git commit --amend -m "Short Message."
**# To reset a commit - or several - use reset**
**# This example, back up 1 commit.**
$ git reset HEAD~1
===== View Changes =====
**# Between staging area and the working tree (commit to push)**
$ git diff
**# General overview of the changes**
$ git status
**# History overview **//-N //**is the number of commits to include (numeric value)**
**# You can append **//--oneline//** for a better overview**
$ git log -p (-N)
===== Branches =====
**# Added features, or bug-fixes, is usually tested in Branches. **
**#** **Once the changes are as pleased, they can be committed and then merged with the master branch.**
**# Create a branch which name accurately reflects its purpose**
$ git branch //<BRANCH_NAME>//
**# List branches**
$ git branch
**# Switch branches**
$ git checkout //<BRANCH_NAME>//
**# Merge a branch to the master branch**
$ git checkout master
$ git merge //<BRANCH_NAME>//
**# Once done with a branch, delete it**
$ git branch -d //<BRANCH_NAME>//
===== Merge Conflicts =====
**# Whenever git isn't able to merge commits/branches together**
**# you will have to solve the conflict yourself.**
**# Navigate to your project folder and run a **//git status//** for more information**
**# Open the file(s) that are in conflict - with your favorite editor of course!^**
**# The conflict will be marked within **//<<<< ===== >>>> //** markers.**
<<<<<<< HEAD
**# You local branch data**
======
**# Other branch data**
>>>>>>> //branchname//
**# Decide and make the changes that is wanted/needed. Remove the markers as well. **
**# Once the document looks like you want it, stage the changes**
$ git add . **# note the dot (.)**
**# Then commit the changes **
$ git commit -m "Resolved merge conflict."
===== Remote Repositories =====
**#** **Remote locations, like Github, can work in collaboration with your local repository.**
**#** **Add your **//SSH public key//** to Github and run your **//SSH agent//**.**
**#** **In below examples the **///Stickano/hello-world //**Github account and repository is used.**
**#** **The SSH connection to this account would be **ssh://[email protected]/Stickano/hello-world
== Clone a repository ==
**# Say you've created a new repository on Github**
**# Create a new folder for the dump**
$ mkdir ~///<FOLDER_NAME>//
**# Clone the repository**
$ git clone ssh://[email protected]/Stickano/hello-world //<FOLDER_NAME>//
**# This will also create a label (see below) for the original location. This label is called **//origin//
== Pull request ==
**# A pull request will download the latest changes from the remote repository, **
**#** **so that you can merge it with your own.**
**# To fetch (download changes) and view the changes**
$ git fetch ssh://[email protected]/Stickano/hello-world master
$ git log -p HEAD..FETCH_HEAD
**# To merge master branches**
**# Remember to **//checkout master//** branch if you aren't already on it.**
$ git merge FETCH_HEAD
== Push repository ==
**# Once your local master branch (this example) has merged changes, **
**#** **you can push (upload) to remote repository.**
**# To push the current branch to the remote repository, FIRST TIME use**
$ git push ssh://[email protected]/Stickano/hello-world //-u//
**# Since the clone tool create a **//origin//** label, it would often look like this (FIRST TIME)**
$ git push -u origin
**# The **//-u//** option will record the location, so next time you just have to use**
$ git push
**# Push a specific branch to remote repository. The branch will be created in it doesn't exist remote.**
$ git push origin //<BRANCH_NAME>//
**# Push current branch to the same name on remote repository**
$ git push origin HEAD
== Label your remote repository ==
**# NOTE: If you cloned a repository, it has already been labeled**// origin//
**# We can label our frequent visited remote repositories, like Github, to a meaningful name**
$ git remote add //<LABEL_NAME> //ssh://[email protected]/Stickano/hello-world
**#** **Fetch a label**
$ git fetch //<LABEL_NAME>//
**# Show difference between local master and remote master**
$ git log -p master..//<LABEL_NAME>///master
**# To view which label is used for current repository**
$ git remote -v
===== Tips and Tricks =====
**#** **Some random Tips and Tricks**
== Auto completion with Bash commands (Bash) ==
**# To add auto-complete on Git commands in your terminal, add the following to your **//.zshrc//** file**
{{{code: lang="texinfo" linenumbers="True"
source /usr/share/git/completion/git-completion.bash
}}}
== Aliases ==
**# Consider these aliases for your **//~/.zshrc//** file**
{{{code: lang="texinfo" linenumbers="True"
alias such=git
alias very=git
alias wow='git status'
}}}
**# Would produce**
$ wow
$ such commit
$ very push