-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRename_Git_Branch_Locally_And_On_Remote_Server.ps1
More file actions
61 lines (48 loc) · 2.28 KB
/
Rename_Git_Branch_Locally_And_On_Remote_Server.ps1
File metadata and controls
61 lines (48 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# https://stackoverflow.com/questions/2003505/how-do-i-delete-a-git-branch-locally-and-remotely
######################
###### This script should be executed manually, step by step
###### Use GitLab UI to control changes
######
###### This control script renames git branch, both locally and on the server.
###### It serves as "post-production-steps-for-new-release-spring-release"
######
###### The principle applied here is to:
######
###### 1. delete branch from remote
###### 2. rename branch locally
###### 3. push a renamed branch to the server
###### 4. check if devel-$future_release exists - either locally or on remote server,
###### then if not, create devel-cur-$future_release and push to server
######################
########### Edit your numbers here
$release_in_question='9.0.3.2390.02'
$future_release='9.0.3.2390.03'
git checkout master
# get latest from remote
git pull --all
# start with remotes: delete remote branch named devel-cur-*
#git push origin --delete --force $(git branch --list 'devel-cur-*')
git push origin --delete --force "devel-cur-$release_in_question"
# 1. rename local branch to a different name
git branch -m "devel-cur-$release_in_question" "prod-$release_in_question"
# push this newly renamed branch to gitlab, will become protected branch
git push origin "prod-$release_in_question":"prod-$release_in_question"
# 2. rename next release to become devel-cur
# if devel-$future_release does not exist, use git checkout init-branch and there
# git checkout -b devel-cur-$future_release
$dev_branch = 'devel-$future_release'
$locally_new_branch_exists = git show-ref refs/heads/$dev_branch
$remotely_new_branch_exists = git ls-remote --heads origin $dev_branch
If ($locally_new_branch_exists -ne $null -and $remotely_new_branch_exists -ne $null) {
# use below to checkout init-file branch (e.g. it can contain some created folders, files, etc.)
# and start a new release from there
git checkout init-branch
git checkout -b devel-cur-$future_release init-branch
} else {
git branch -m $dev_branch "devel-cur-$future_release"
}
# push this newly renamed branch to gitlab
git push origin "devel-cur-$future_release":"devel-cur-$future_release"
# delete remote branch, making it clean
git push origin --delete --force $dev_branch
# check manually Git(Hub/Lab)