Tuesday, August 29, 2023

Merge branches in Git

 

GIT


In your local Git, create a directory test and then change directory to test.
check out the branches and then create a branch called test. 


Switch to the branch test

mkdir test; cd test
 

git branch
 

git checkout -b test -> you will be switched to test branch
 

git branch

Create a file and then run the following git commands

git add .
 

git commit -m "commit message"
 

git push origin test -> Very important as you are pushing it from test branch (most make mistakes and uses git push origin master)
This push from test branch shows that, we need to create a pull request for 'test' on GitHub on the link - https://github.com/yashwanthsn2020/automation/pull/new/test
If you wish to delete test branch, you can do so by switching to master and then run
git branch -D test

On the GitHub, the file is successfully pulled
Check out the local master repo, we still have 3 files and test_branch_script.sh is not present
run git pull origin master and the new file will be pulled to the local master repo
Note: When you are on local master repo use git push origin master and when you are the different branches other than master run git push origin <branch_name>. In my case it was git push origin test