|
| 1 | +& "C:\Program Files (x86)\Info Keep\info keep.exe" |
| 2 | + |
| 3 | +Photography Co-worker Kevin Hecht (kevin.a.hecht@pwc.com) |
| 4 | + |
| 5 | +# git config commands |
| 6 | + |
| 7 | +- ps.readinglist.md -- Quick Reference Reading list of helpful PowerShell sites, articles, and documents |
| 8 | + |
| 9 | +### Support for Long Paths |
| 10 | + |
| 11 | +git config --system core.longpaths true |
| 12 | + |
| 13 | +### git remote urls |
| 14 | + |
| 15 | +git remote -v |
| 16 | + |
| 17 | +## User Config |
| 18 | + |
| 19 | +### To Set your username |
| 20 | + |
| 21 | +git config --global user.name "FIRST_NAME LAST_NAME" |
| 22 | + |
| 23 | +### To Set your email address |
| 24 | + |
| 25 | +git config --global user.email "MY_NAME@example.com" |
| 26 | + |
| 27 | +git config --global user.name "Brooks Vaughn" |
| 28 | +git config --global user.email "18422308+BrooksV@users.noreply.github.com" |
| 29 | + |
| 30 | +git config --worktree user.name "Brooks Vaughn" |
| 31 | +git config --global user.email "18422308+BrooksV@users.noreply.github.com" |
| 32 | + |
| 33 | +### Check configuration for your user |
| 34 | + |
| 35 | +$ cat $HOME/.gitconfig |
| 36 | + |
| 37 | +## Proxy Config |
| 38 | + |
| 39 | +### Get system value |
| 40 | + |
| 41 | +git config --system --get https.proxy |
| 42 | +git config --system --get http.proxy |
| 43 | + |
| 44 | +### Get global value |
| 45 | + |
| 46 | +git config --global --get https.proxy |
| 47 | +git config --global --get http.proxy |
| 48 | + |
| 49 | +### Unset system value |
| 50 | + |
| 51 | +$ git config --system --unset https.proxy |
| 52 | +$ git config --system --unset http.proxy |
| 53 | + |
| 54 | +### Unset global value |
| 55 | + |
| 56 | +$ git config --global --unset https.proxy |
| 57 | +$ git config --global --unset http.proxy |
| 58 | + |
| 59 | +## Proxy Config using Environment Variables |
| 60 | + |
| 61 | +Your proxy could also be set as an environment variable. Check if your environment has any of the env variables http_proxy or https_proxy set up and unset them. Examples of how to set up: |
| 62 | + |
| 63 | +### Linux |
| 64 | + |
| 65 | +export http_proxy=http://proxy:8080 |
| 66 | +export https_proxy=https://proxy:8443 |
| 67 | + |
| 68 | +### Windows |
| 69 | + |
| 70 | +set http_proxy http://proxy:8080 |
| 71 | +set https_proxy https://proxy:8443 |
| 72 | + |
| 73 | +## SSL Config |
| 74 | + |
| 75 | +git config --global http.sslVerify |
| 76 | +git config --global http.sslVerify true |
| 77 | + |
| 78 | +### Repro Clone SSL Errors |
| 79 | + |
| 80 | +SSL_VERIFY=false |
| 81 | +git config --global http.sslVerify false |
| 82 | + |
| 83 | +My agents are running as Network Service too but that wasn't really a problem to use user level config. Here is what I did: |
| 84 | +1.Save all the necessary certificates in folder %systemroot%\ServiceProfiles\NetworkService\.gitcerts\. |
| 85 | +2.Create a file at %systemroot%\ServiceProfiles\NetworkService\.gitconfig with the following content: |
| 86 | + |
| 87 | +[http "https://tfs.com/"](http "https://tfs.com/") |
| 88 | + sslCAInfo = ~/.gitcerts/certificate.pem |
| 89 | + |
| 90 | +[adding-a-corporate-or-self-signed-certificate-authority-to-git-exes-store](https://blogs.msdn.microsoft.com/phkelley/2014/01/20/adding-a-corporate-or-self-signed-certificate-authority-to-git-exes-store/) |
| 91 | + |
| 92 | +git config --global http.sslBackend schannel |
| 93 | + |
| 94 | +[how-to-make-git-work-with-self-signed-ssl-certificates-on-tfs2018](https://www.benday.com/2017/12/15/how-to-make-git-work-with-self-signed-ssl-certificates-on-tfs2018/) |
| 95 | +[fix-git-self-signed-certificate-in-certificate-chain-on-windows](https://mattferderer.com/fix-git-self-signed-certificate-in-certificate-chain-on-windows) |
| 96 | + |
| 97 | +# Git Repo and Branch Commands |
| 98 | + |
| 99 | +### Reset Local Master |
| 100 | + |
| 101 | +git fetch origin master |
| 102 | +git checkout master |
| 103 | +git reset --hard origin/master |
| 104 | +git reset origin/master --hard |
| 105 | +git pull origin master |
| 106 | + |
| 107 | +### Reset Local Main |
| 108 | + |
| 109 | +git fetch origin main |
| 110 | +git checkout main |
| 111 | +git reset --hard origin/main |
| 112 | +git pull origin main |
| 113 | + |
| 114 | +If you want to create a new branch to retain commits you create, you may do so (now or later) by using -c with the switch command. |
| 115 | + |
| 116 | +Example: |
| 117 | + git switch -c <new-branch-name> |
| 118 | + |
| 119 | +Or undo this operation with: |
| 120 | + git switch - |
| 121 | + |
| 122 | +## Status and Info Commands |
| 123 | + |
| 124 | +git status |
| 125 | +git log |
| 126 | +git branch --all |
| 127 | +git branch features/<Branch name> |
| 128 | + |
| 129 | + |
| 130 | +git fetch origin |
| 131 | +git fetch origin master |
| 132 | +git checkout master |
| 133 | +git pull origin master |
| 134 | +git checkout features/<Branch name> |
| 135 | +git merge branch master |
| 136 | +git status |
| 137 | +git log |
| 138 | +git push |
| 139 | + |
| 140 | + |
| 141 | +git pull |
| 142 | +git branch -a |
| 143 | + |
| 144 | +## To Create Branch from Master |
| 145 | + |
| 146 | +git fetch origin master |
| 147 | +git checkout master |
| 148 | +git pull origin master |
| 149 | +git checkout -b features/??? |
| 150 | +git push --set-upstream origin features/??? |
| 151 | +git checkout features/??? |
| 152 | + |
| 153 | +### Create local branch |
| 154 | + |
| 155 | +git checkout -b features/<branch name> |
| 156 | +git status |
| 157 | +git add foo.txt |
| 158 | +git commit -m "<comment>" |
| 159 | +git commit -a -m "<comment>" # ? |
| 160 | +git push |
| 161 | + |
| 162 | +### Create Branch on origin (UpStream) to Repository |
| 163 | + |
| 164 | +git push --set-upstream origin features/<branch name> |
| 165 | + |
| 166 | +### To sync local master |
| 167 | + |
| 168 | +git checkout master |
| 169 | +git pull |
| 170 | + |
| 171 | +git checkout features/readme-updates |
| 172 | +git merge master ???? |
| 173 | + |
| 174 | +# Notes |
| 175 | + |
| 176 | +Origin is the plcae where the branch was cloned from |
| 177 | + |
| 178 | +git remote add <name> <url> |
| 179 | +git add -p |
| 180 | +git log --online |
| 181 | + |
| 182 | +npm config set strict-ssl false |
| 183 | + |
| 184 | + |
| 185 | +# Git Merging commands |
| 186 | + |
| 187 | +git merge branch master |
| 188 | +git status |
| 189 | +git log |
| 190 | +git push |
| 191 | + |
| 192 | + |
| 193 | +git config --get --local core.filemode |
| 194 | +false |
| 195 | + |
| 196 | +git config --local --list |
| 197 | + |
| 198 | +## Commits |
| 199 | + |
| 200 | +git add yaml\???.yml |
| 201 | +git commit -m "???" |
| 202 | +git commit -a -m "<comment>" # ? |
| 203 | +git push |
| 204 | +git merge --abort |
| 205 | +git branch -a --sort=-committerdate --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))' |
| 206 | +(git reflog > reflog.md) | Invoke-Item |
| 207 | +git reflog | Select-String <issue trackerID> |
| 208 | + |
| 209 | +### Explanation of what each of those Git commands do |
| 210 | + |
| 211 | +### `git add yaml???.yml` |
| 212 | + |
| 213 | +- **Description**: Adds files matching the pattern `yaml???.yml` to the staging area. |
| 214 | +- **Wildcard**: The `???` matches exactly three characters, so this would match files like `yaml123.yml` or `yamlABC.yml`. |
| 215 | +- **Example**: `git add yaml123.yml` or `git add yamlABC.yml`. |
| 216 | + |
| 217 | +### `git commit -m "???"` |
| 218 | + |
| 219 | +- **Description**: Commits the staged changes to the repository with a commit message `"???"`. |
| 220 | +- **Purpose**: The message `"???"` is a placeholder and should be replaced with a meaningful description of the changes. |
| 221 | +- **Example**: `git commit -m "Added new YAML configuration files"`. |
| 222 | + |
| 223 | +### `git commit -a -m ""` |
| 224 | + |
| 225 | +- **Description**: Commits all changes to tracked files (bypassing the staging area) with an empty commit message. |
| 226 | +- **Purpose**: This is unusual because an empty commit message is generally not recommended. It's better to provide a meaningful commit message. |
| 227 | +- **Example**: `git commit -a -m "Updated configuration files"`. |
| 228 | + |
| 229 | +### `git push` |
| 230 | + |
| 231 | +- **Description**: Pushes the committed changes from your local repository to the remote repository. |
| 232 | +- **Purpose**: Sends your local commits to the remote repository (e.g., GitHub). |
| 233 | +- **Example**: `git push origin master`. |
| 234 | + |
| 235 | +### `git merge --abort` |
| 236 | + |
| 237 | +- **Description**: Aborts the current merge process and attempts to revert the repository back to the state before the merge began. |
| 238 | +- **Purpose**: Used when a merge conflict occurs, and you decide to cancel the merge and resolve conflicts later. |
| 239 | +- **Example**: `git merge --abort` while in the middle of a conflicting merge. |
| 240 | + |
| 241 | +### `git branch -a --sort=-committerdate --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'` |
| 242 | + |
| 243 | +- **Description**: Lists all branches sorted by the most recent commit date, with a custom format for the output. |
| 244 | +- **Purpose**: Provides a detailed, color-coded list of branches, showing which branch is current (HEAD), commit hash, subject of the commit, author name, and the date relative to now. |
| 245 | +- **Example**: `git branch -a --sort=-committerdate --format='...'`. |
| 246 | + |
| 247 | +### `(git reflog > reflog.md) | Invoke-Item` |
| 248 | + |
| 249 | +- **Description**: Redirects the output of `git reflog` to a file named `reflog.md` and opens the file. |
| 250 | +- **Purpose**: Records the reflog (history of changes) into a markdown file and opens it in the default text editor. |
| 251 | +- **Example**: `(git reflog > reflog.md) | Invoke-Item`. |
| 252 | + |
| 253 | +### `git reflog | Select-String` |
| 254 | + |
| 255 | +- **Description**: Displays the reflog and filters the results using `Select-String`. |
| 256 | +- **Purpose**: Allows you to search the reflog for specific patterns or keywords. |
| 257 | +- **Example**: `git reflog | Select-String "commit"` to find entries related to commits. |
| 258 | + |
| 259 | +These commands cover a range of Git operations, from staging and committing changes to managing branches and searching through logs. Let me know if you have any more questions or need further details! |
| 260 | + |
| 261 | +## Git Command docs |
| 262 | + |
| 263 | +git remote add upstream |
| 264 | +git fetch upstream |
| 265 | +git rebase upstream/master |
| 266 | +git push origin master --force |
| 267 | + |
| 268 | +### Explanation of what each of those Git commands does: |
| 269 | + |
| 270 | +### `git remote add upstream` |
| 271 | + |
| 272 | +This command adds a new remote repository, typically the original repository from which you forked your project. |
| 273 | + |
| 274 | +```bash |
| 275 | +git remote add upstream <URL> |
| 276 | +``` |
| 277 | + |
| 278 | +- **Purpose**: To add a reference to the original repository (upstream) so you can pull updates from it. |
| 279 | +- **Example**: If you forked a repository on GitHub, you would use the URL of the original repository. |
| 280 | + |
| 281 | +### `git fetch upstream` |
| 282 | + |
| 283 | +This command fetches updates from the `upstream` remote repository. |
| 284 | + |
| 285 | +```bash |
| 286 | +git fetch upstream |
| 287 | +``` |
| 288 | + |
| 289 | +- **Purpose**: To get the latest changes from the upstream repository without merging them into your working branch. |
| 290 | +- **Example**: This updates your local copy of the remote branches from the upstream repository. |
| 291 | + |
| 292 | +### `git rebase upstream/master` |
| 293 | + |
| 294 | +This command rebases your current branch on top of the `master` branch from the `upstream` repository. |
| 295 | + |
| 296 | +```bash |
| 297 | +git rebase upstream/master |
| 298 | +``` |
| 299 | + |
| 300 | +- **Purpose**: To integrate changes from the upstream repository into your current branch by applying your local commits on top of the upstream/master branch. |
| 301 | +- **Example**: Useful for keeping your forked repository up-to-date with the original repository. |
| 302 | + |
| 303 | +### `git push origin master --force` |
| 304 | + |
| 305 | +This command pushes your local `master` branch to the remote repository (origin) with force. |
| 306 | + |
| 307 | +```bash |
| 308 | +git push origin master --force |
| 309 | +``` |
| 310 | + |
| 311 | +- **Purpose**: To overwrite the remote `master` branch with your local changes, even if it results in non-fast-forward updates. |
| 312 | +- **Example**: Use with caution as it can overwrite changes in the remote repository that others may be relying on. |
0 commit comments