Git - After creating a branch from master I have to sync with master to get its source. Why? - merge

I'm finding that after creating a branch from master that the new branch doesn't have the same source code as master. Ultimately I have to sync after creating the branch to make it work. Why is that? The steps below show what I'm doing, or I made a movie of this: https://youtu.be/m0rhpG6Skac
1) In Bitbucket (on the website) I create a new branch (BranchB) from master.
2) I fetch and then checkout BranchB locally
3) I create a text file called BranchB.txt and save it.
4) I use git status to verify that git sees the untracked file
5) I add the file, make a commit, and then push the branch to remote
6) I verify in BitBucket that the branch was just updated and then merge with the master branch (presumably master has branchB.txt at this point)
7) I create a new branch from master called BranchC using Bitbucket website
8) I fetch and checkout BranchC locally verifying that I am on that new branch
9) I find that BranchB.txt is NOT THERE. Why is that???
10) On the BitBucket website, I find that BranchC is two commits behind master.
Why??
11) I sync BranchC with master (a step I wouldn't have thought necessary)
12) I verify that BranchB.txt now exists in BranchC on remote
13) locally I do a git pull and verify that BranchB.txt exists.

Related

Adding different projects in a solution to their own git branches

6 projects in a solution all live on master. Im using mvvm with a repository
I would like to have a Data Model branch, a view model branch, a repository branch, etc.
I have created the repo on git hub, created a branch that was not master and added the project on the requisite branch. When I am done, projects all are still on master, other branches exist but are empty showing only the blank solution I started with
In your local clone, you need to:
create your new branch from your current master (which has all the files)
git rm all the files which are not part of what you want to keep in that branch
commit and push (git push -u origin newBranch)
Repeat (get back to master, which still has all the files) for each new branch.
Finally, go back one last time to master, git rm the files you don't need anymore (because they have been referenced by your new branches), add, commit and push.

Get last modifications from GIT with Visuyal Studio

I tried many procedures to update local branch like SVN Update but impossible to have the good result.
Here is the problem :
I created 2 new branches. In the first branch, I added a new class in a project (test project to write GIT procedure) and commit. Then I made a pull request and validate it to update master (with branch deletion).
My colleague use the second branch and add a new class, but he like to update his repo with last master version (like SVN Update).
How can I do that ?
I tried these manipulations :
- double clic on local master and Pull button to update local master, and merge local master to local branch : don't works
- on local branch, pull button but error message (some modifications have not been saved...)
- Sync button : don't works
To resume, if a developper start to develop on a branch and after many days, want to get the last version of remote master to merge on his lacal branch, how can he do ?
Thanks

Merging branches with Pycharm using Github repo

What is the correct way to merge two branches of a Github project with Pycharm?
Suppose there is a branch in a Github project called master and I clone the repo with Pycharm. After that, I create a new branch dev by using Pycharm. The new branch is then shown correctly on Github and some commits are made to the branch.
Now, I want to merge the changes from the dev branch to the master branch.
For ordinary git (not Github) projects, I would checkout to the local master in Pycharm, click on dev in the local branch and select the merge context menu. As a result, dev would be merged to master such that it can be safely deleted.Though, even after I merge the local master with the remote master branch, no changes are shown on Github and both branches still exist.
I also tried to close Pycharm, do a pull request on Github, merge the branches there and restart Pycharm. Unfortunately, Pycharm doesn't even recognize that the remote dev branch has been deleted.
My subpar solution has been as follows:
Pycharm: Merge local dev to local master, delete local dev, merge local
master with remote master
Github: Create PR, merge branches, delete dev
Pycharm: Delete remote dev
Now, if I rebase onto the remote master in Pycharm, I get the correct merged branch. Unfortunately though, using the compare context menu, Pycharm still shows that the remote master compared to the local master doesn't have the commits from dev. Although a rebase from the remote master contains all the commits from dev...
Sadly, there's also no Pycharm manual for merging branches with Github (for normal git there is). Any idea?
The solution is to manually push your branch merge as it seems that pycharm doesn't do this, but it thinks it has.
I've noticed the same issue and it seems that the merge is not pushed from the local copy. In a command shell I checkout the master branch of my project and it tells me that I am ahead of online repository, so to resolve this I issue the git push command and then when I check github it has been uploaded.
(tf36) E:\git\alpha-zero-theputernerd>git checkout master
Already on 'master'
A src/alpha_zero/env/env_inherit_from.py
Your branch is ahead of 'origin/master' by 3 commits.
(use "git push" to publish your local commits)
(tf36) E:\git\alpha-zero-theputernerd>git push
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/theputernerd/alpha-zero-theputernerd.git
bb60325..37c3c9d master -> master

Within Eclipse, switch from using the Master branch in the Local Repository to something else

I created an empty project in Git. I also created a Java EE projcet in Eclipse (note: Eclipse has the Git plug-in installed).
From within Eclipse, I accessed and duplicated the (empty) Git Repository project on my Local Machine (or rather laptop).
I then wrote some code in my Java EE project.
From within the project, I then used the Team -> Commit option on it to :
1) Add the project to the Local Repository
2) Commit and push the contents from the Local Repository to the Git Repository.
My problem is that all of this work was done using the Master branch.
The Git Repository is currently sitting on the Master branch.
The Local Repository is currently sitting on the Master branch.
Whenever I make changes to the project and do a Team-> Commit, all actions happen with the Master branches.
Master -> Master
What I would like to do is as follows:
1) create 3 more branches in Git Repository (called consolidation, testing, production) - each new branch would be a copy of the Master Branch
2) On the Eclipse side, I need to fix it so that when any changes are made and saved to the Local Repository, the data will be saved to the
Consolidation Branch of the Local Repository and ~NOT~ the Master Branch (which is what happens now).
3) After saving data in the Consolidation Branch, from then on out, when code is sent to the Git Repository, it would be done by using the Consolidation branch and NOT the Master branch.
How can I do this?
TIA
Update
#Howlger
Hi and thanks for the response! Your suggestion gave me a clue on how to solve the problem. First, I logged into Git and copied the Master branch to a "dev" branch.
Next, I switched to the Git perspective (locally) under Eclipse and created a "dev" branch for my project:
Branches -> Switch To -> New Branches
Then, I followed some of your advice except I created a path that would allow for
branch : dev (local) => branch : dev (remote)
It is under the "Advanced" button.
I did a small test and it worked. Thanks again!
Update
Hi again - just logging in to note that I changed the references so that
Source Ref = refs/heads/*
Target Ref = refs/heads/*
The mapping of a local branch to a branch of the remote/upstream repository is specified by the push ref mappings. It looks like your current push ref mapping is HEAD:refs/heads/master: your current local branch will be pushed to the remote/upstream repository master branch. To map local branches to the remote/upstream repository branches with the same name, just remove all push ref mappings:
In the Git Repositories view righ-click the Remotes > origin > push node and choose Configure Push...
Select the mapping and click Delete
Click Save
See EGit User Guide > Push Ref Specifications for more details.

How to script GIT MERGE commands to automate it in GitLab

My requirement is little different from regular branch merge.
It is something like
Branches in my local and server repo -> Branch-1, Branch-2 & Master
On the event of…
creating a merge request.
pushing changes to the head/source branch
pushing changes to the base/target branch
…do…
attempt a merge of the HEAD/source onto the target.
EG: (git clone target, git remote add source..., git fetch source. git checkout -b attempted-merge; git merge..)
push a new ref to the repo “refs/merge-requests/{id}/head” (git push origin target/:merge-requests/{id}/head)
If there were no merge conflicts, push “refs/merge-requests/{id}/merge” (git push origin attempted-merge:merge-requests/{id}/merge)
Comment on the merge request with the status (using :+1: or :-1: to include a vote of approval)
In this process we are creating a new branch called ATTEMPTED-MERGE. But this branch while pushed should not exactly be pushed to the server instead it should be given a new REFS name (EG: refs/merge-request/{ID}/merge).
So this would actually contains the merge but is not been pushed to the server instead stored in a temporary location where it can been seen in local repo but not in remote repo. This is because of validating the merge and authorizing the merge to actually happen if everything is correct (means if all the code is there as expected and ready for a clean merge). Then once approved it will be merged on the remote repo.
This is the scenario which i have right now. Not able to understand how to do this in SCRIPT and make it automate so that this script should run when a merge is requested.
Inputs to this script are
Source URL, Source Branch, Target URL & Target Branch.
Once these are given the script should run and depending on the input values it should perform the merge in GITLAB.
Can any one help me out how to do this .. !!!!