diff --git a/input/posts/pwsh/git-config-switch-using-powershell-script.md b/input/posts/pwsh/git-config-switch-using-powershell-script.md index 7a177bb..df6274d 100644 --- a/input/posts/pwsh/git-config-switch-using-powershell-script.md +++ b/input/posts/pwsh/git-config-switch-using-powershell-script.md @@ -17,33 +17,6 @@ Overview of the script, ## final script ```powershell -# Copyright (c) iQubit Inc. -<# -.Synopsis - Switch git config -.DESCRIPTION - Switch to provided git config profile. Runs series of git config commands. - Suggests updating GH Token - ToDo: - Fow now, go with this.. - provide Force flag - probably read from a local json config file - too many params to pass otherwise.. - - facilitate proper checkout with GitUtil - - Demonstrates, - - switch syntax - - case insensitive string comparison: [System.StringComparison] - -.Parameter ProfileName - Select among available profiles -.Parameter CredUserNames - Available git user names -.EXAMPLE - Switch-GitConfig.ps1 USER_NAME_1 @('USER_NAME_1', 'USER_NAME_2') -#> - [CmdletBinding()] param( [ValidateSet('USER_NAME_1', 'USER_NAME_2')] @@ -125,6 +98,11 @@ function VerifyGitProfile() { git config --get credential.username } - Main -``` \ No newline at end of file +``` + +Copy of this script (including documentation) can be found at: +https://github.com/atiq-cs/old-scripts/blob/dev/pwsh/Switch-GitConfig.ps1 + +More scripts like this can be found at: +https://github.com/atiq-cs/old-scripts/blob/dev/pwsh diff --git a/input/posts/scm/git.md b/input/posts/scm/git.md index 9656e8e..36f29c4 100644 --- a/input/posts/scm/git.md +++ b/input/posts/scm/git.md @@ -331,37 +331,47 @@ Accept their change for single file, ref git checkout --theirs src/register-configuration.cc -## Origin tricks and Branches -Change repository URL, - - git remote set-url origin https://github.com/user_name/testing.git - -switch to a new branch, +### Branches +Create new branch from current branch's tip and switch to newly created branch, git checkout -b dev_branch -show current branch and other branches, +Show current branch and other branches, git branch -Delete a branch on your local filesystem, - - git branch -d testing_branch +Delete a branch on your local repo, -The git push syntax is: git push [remote-repository-name] [branch-or-commit-name], + git branch --delete branch_already_merged - git push origin dev_branch - -Change remote origin, +Delete a branch from remote, - git remote set-url origin URL + git push origin --delete main -## Detached Head +Created detached head (no branch) If we want our git repo to have no current branch then we can do this, git checkout COMMIT-SHA-ID +### Remote Origin Related +Change remote URL syntax, + + git remote set-url origin_name URL + +Example, + + git remote set-url origin https://github.com/user_name/repo_name.git + +Add an origin to a just initialized repo, + + git remote add origin https://github.com/user_name/repo_name.git + +git push examples, + + git push [remote-name] [branch-or-commit-name] + git push origin dev_branch + ## Git configuration Files When we perform `git config` it applies only to the current project. The configuration file that gets update is, @@ -377,14 +387,17 @@ If none of these exist then the systems git config file is applied. According to ~/.gitconfig /etc/gitconfig (guessing I don't recall the exact location) +Push the renamed branch to remote and set upstream, -## Github Commands -Rename branch + git push origin --set-upstream dev +### Github UseCase Examples +**Renaming main branch** +1. Rename branch git branch --move main dev -Using github UI set default branch to dev now visiting following URL, +2. Using github UI, let's set default branch to dev, visiting following URL, ``` https://github.com/USER/REPO/settings/branches @@ -392,11 +405,9 @@ https://github.com/USER/REPO/settings/branches Please replace `USER` and `REPO` with correct user name and repository name. - git push origin --delete main - -Push the renamed branch to remote and set upstream, +3. Finally, delete the branch from remote, - git push origin --set-upstream dev + git push origin --delete main ## References