Skip to content

Commit e257c6b

Browse files
committed
Merge pull request #54 from patrickwalkowicz/master
Added a section on git mv and updated cheatsheet.md accordingly
2 parents 94b3259 + 306ed7a commit e257c6b

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Git for Collaboration is aimed at the second week students of the course, or tho
1919
* [Making Changes](#changes)
2020
* [Merging with Master](#merging)
2121
* [Merge Conflicts](#conflicts)
22+
* [Changing File Structure](#changing-file-structure)
2223
4. [Introducing Github Flow](#github-flow)
2324

2425
#### [Git for Collaboration](#git-collaboration)
@@ -276,6 +277,39 @@ Do you see the lines at the top. The first section is labelled `HEAD` those are
276277
Afterwards git status, add the files in red, commit, and push. Then make a pull request to master like before and merge. Don't forget to update your local master branch, and delete the merged branch in Github and in your local repo. It is good to keep your working environments clean and organised.
277278
278279
280+
<a id="changing-file-structure" name="changing-file-structure"></a>
281+
### Changing File Structure
282+
Imagine you're working on a project that's getting bigger in size. As new files are added, it makes sense to group some of them into folders. For example, it's a good idea to keep all CSS files in one folder, JS files in another etc.
283+
284+
Let's assume you've just cloned a repository structured like this:
285+
```
286+
index.html
287+
stylesheet.css
288+
script.js
289+
```
290+
291+
However, you'd prefer to split these into folders like:
292+
```
293+
css/stylesheet.css
294+
js/script.js
295+
index.html
296+
```
297+
298+
In order to achieve this, `git mv` command comes in handy. Using it to move files *ensures preserving history* of the files you work on. To change file structure like above (and create new folders at the same time) use command:
299+
```
300+
mkdir css && git mv stylesheet.css ./css
301+
mkdir css && git mv script.js ./js
302+
```
303+
(This glues `mkdir` and `git mv` commands together with `&&` operator).
304+
305+
Basic function usage is
306+
```
307+
git mv <source> <destination>
308+
```
309+
The command also takes optional parameters. To find out more, refer to [documentation](http://git-scm.com/docs/git-mv).
310+
311+
312+
279313
<a name="github-flow" id="github-flow"></a>
280314
## Github Flow
281315
Github flow is what most teams at Founders & Coders follow. It is simple and effective.

cheatsheet.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717

1818
##### Deleting a branch
1919
git branch -d <branch name>
20+
21+
##### Moving files while preserving git history
22+
git mv <source> <destination>
2023

0 commit comments

Comments
 (0)