|
1 | | -author: Sergei and Andy |
| 1 | +Working with PowerShell repository |
| 2 | +================================== |
2 | 3 |
|
| 4 | +#### Get the code for the first time |
3 | 5 |
|
| 6 | +```sh |
| 7 | +git clone --recursive https://github.com/PowerShell/PowerShell |
| 8 | +``` |
4 | 9 |
|
5 | | ->getting started working with PowerShell github |
6 | | ->branch structure intro |
7 | | - > branching (and folder) structure (where do I submit PRs? where's the release branch? dev branch? working branch?) |
8 | | ->PR process and requirements |
9 | | -> more |
| 10 | +PowerShell repository has **submodules**. |
| 11 | +They are required to build and test powershell. |
| 12 | +That's why you need `--recursive`, when you `clone`. |
| 13 | + |
| 14 | + |
| 15 | +If you already cloned the repo without `--recursive`, update submodules manually |
| 16 | + |
| 17 | +```sh |
| 18 | +git submodule init |
| 19 | +git submodule update |
| 20 | +``` |
| 21 | + |
| 22 | +See [FAQ](../FAQ.md#why-is-my-submodule-empty) for details. |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +Branches |
| 27 | +--------- |
| 28 | + |
| 29 | +* Don't commit your changes directly to master. |
| 30 | + It would make workflow messy. |
| 31 | +* Checkout a new local branch from master for every change you want to make (bugfix, feature). |
| 32 | +* Use `alias/feature-name` pattern. |
| 33 | +* Use lowercase-with-dashes for naming. |
| 34 | +* Follow [Linus' recommendations][Linus] about history. |
| 35 | + - People can (and probably should) rebase their _private_ trees (their own |
| 36 | + work). That's a _cleanup_. But never other peoples code. That's a "destroy |
| 37 | + history" |
| 38 | + - You must never EVER destroy other peoples history. You must not rebase |
| 39 | + commits other people did. Basically, if it doesn't have your sign-off |
| 40 | + on it, it's off limits: you can't rebase it, because it's not yours. |
| 41 | + |
| 42 | +#### Understand branches |
| 43 | + |
| 44 | +* **master** is the branch with the latest and gratest changes. |
| 45 | + It could be unstable. |
| 46 | +* Send your Pull Requests to **master**. |
| 47 | + |
| 48 | +#### Sync your local repo |
| 49 | + |
| 50 | +Use **git rebase** instead of **git merge** and **git pull**, when you updating your feature-branch. |
| 51 | + |
| 52 | +```sh |
| 53 | +# switch to master branch |
| 54 | + |
| 55 | +# fetch updates all remote branch references in the repo and all submodules |
| 56 | +# --all : tells it to do it for all remotes (handy, when you use your fork) |
| 57 | +# -p : tells it to remove obsolete remote branch references (when they are removed from remote) |
| 58 | +git fetch --all -p |
| 59 | + |
| 60 | +# pull updates your local files |
| 61 | +# you should call this command ONLY from master branch |
| 62 | +git pull origin master |
| 63 | + |
| 64 | +``` |
| 65 | + |
| 66 | +Then switch to your branch and do rebase |
| 67 | + |
| 68 | +``` |
| 69 | +git rebase master |
| 70 | +``` |
| 71 | + |
| 72 | +#### Git pretty |
| 73 | + |
| 74 | +[So you have a mess on your hands?](http://justinhileman.info/article/git-pretty/) |
| 75 | + |
| 76 | +[Linus]:http://thread.gmane.org/gmane.comp.video.dri.devel/34739/focus=34744 |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | +Tags |
| 82 | +------ |
| 83 | + |
| 84 | +If you are looking for the source code for a particular release, |
| 85 | +you will find it via **tags**. |
| 86 | + |
| 87 | +* `git tag` will show you list of all tags. |
| 88 | +* Find the tag that corresponds to the release. |
| 89 | +* Use `git checkout <tag-name>` to get this version. |
| 90 | + |
| 91 | +**Note:** [checking out tag][] will move the repo in [DETACHED HEAD][] state. |
| 92 | + |
| 93 | +[checking out tag]:https://git-scm.com/book/en/v2/Git-Basics-Tagging#Checking-out-Tags |
| 94 | +[DETACHED HEAD]:https://www.git-tower.com/learn/git/faq/detached-head-when-checkout-commit |
| 95 | + |
| 96 | +If you want to make changes, based on tag's version (i.e. a hotfix), |
| 97 | +checkout a new branch from this DETACHED HEAD state. |
| 98 | + |
| 99 | +```sh |
| 100 | +git checkout -b vors/hotfix |
| 101 | +``` |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | +Recommended Git configurations |
| 106 | +============================== |
| 107 | + |
| 108 | +We highly recommend these configurations to help deal with whitespace, |
| 109 | +rebasing, and general use of Git. |
| 110 | + |
| 111 | +> Auto-corrects your command when it's sure (`stats` to `status`) |
| 112 | +```sh |
| 113 | +git config --global help.autoCorrect -1 |
| 114 | +``` |
| 115 | + |
| 116 | +> Refuses to merge when pulling, and only pushes to branch with same name. |
| 117 | +```sh |
| 118 | +git config --global pull.ff only |
| 119 | +git config --global push.default current |
| 120 | +``` |
| 121 | + |
| 122 | +> Shows shorter commit hashes and always shows reference names in the log. |
| 123 | +```sh |
| 124 | +git config --global log.abbrevCommit true |
| 125 | +git config --global log.decorate short |
| 126 | +``` |
| 127 | + |
| 128 | +> Ignores whitespace changes and uses more information when merging. |
| 129 | +```sh |
| 130 | +git config --global apply.ignoreWhitespace change |
| 131 | +git config --global rerere.enabled true |
| 132 | +git config --global rerere.autoUpdate true |
| 133 | +git config --global am.threeWay true |
| 134 | +``` |
0 commit comments