Tuesday, 24 November 2020

git create branch, merge branch

//create a new repository with new txt file in master
 git add .
git commit -m "1"

[master (root-commit) 9455543] 1
 1 file changed, 1 insertion(+)
 create mode 100644 New Text Document.txt

git remote add origin https://github.com/chuanshuoge6/test.git
git push -u origin master

Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 219 bytes | 219.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/chuanshuoge6/test.git
 * [new branch]      master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
repository master has a txt with abc in it
//create a branch of master
git checkout -b branch1

Switched to a new branch 'branch1'

git push origin branch1

Total 0 (delta 0), reused 0 (delta 0)
remote:
remote: Create a pull request for 'branch1' on GitHub by visiting:
remote:      https://github.com/chuanshuoge6/test/pull/new/branch1
remote:
To https://github.com/chuanshuoge6/test.git
 * [new branch]      branch1 -> branch1
branch1 created

branch1 has same file as master
//make change on branch1
git add .
git commit -m "2"

[branch1 e32762d] 2
 1 file changed, 2 insertions(+), 1 deletion(-)

git push -u origin branch1

Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Writing objects: 100% (3/3), 251 bytes | 251.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/chuanshuoge6/test.git
   9455543..e32762d  branch1 -> branch1
Branch 'branch1' set up to track remote branch 'branch1' from 'origin'.
branch1 txt file is added a line "bcd"
//switch to master
git checkout master

Switched to branch 'master'
Your branch is up to date with 'origin/master'.

//merge branch1 to master
git merge branch1

Updating 9455543..e32762d
Fast-forward
 New Text Document.txt | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

git push

Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/chuanshuoge6/test.git
   9455543..e32762d  master -> master
master is merged by branch1, master has a new line "bcd" from branch1

//delete branch1
git branch -d branch1

Deleted branch branch1 (was e86d57c).

git push origin :branch1

To https://github.com/chuanshuoge6/test.git
 - [deleted]         branch1
branch1 is removed
reference:


No comments:

Post a Comment