Skip to content

Commit

Permalink
git-config-switch-using-powershell-script.md
Browse files Browse the repository at this point in the history
- documentation moved to the repo version of the script

scm/git.md
- Move parts to right sections for branches, remote etc
  • Loading branch information
atiq-cs committed Dec 2, 2021
1 parent 7bdcc9c commit 38e6e26
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 52 deletions.
36 changes: 7 additions & 29 deletions input/posts/pwsh/git-config-switch-using-powershell-script.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')]
Expand Down Expand Up @@ -125,6 +98,11 @@ function VerifyGitProfile() {
git config --get credential.username
}
Main
```
```

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
57 changes: 34 additions & 23 deletions input/posts/scm/git.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -377,26 +387,27 @@ 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
```

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
Expand Down

0 comments on commit 38e6e26

Please sign in to comment.