how to work in a new branch on eclipse? - java

I'm trying to learn how to use GitHub.
I managed to create a repository and update the master,
But I'm trying to understand how the branching is working.
I have created a new branch on eclipse by right clicking the master and then "Create branch..." button.
After that I double-clicked it to work on this branch, and I added a new class to see if I am working on this branch.
But when I'm going back to the master that class is already there, and I did not used the merge command...
In the project explorer the content on the [...] after the project's name has change to the new branch's name, which I will assumed means that I'm working on a different branch.
So, what am I doing wrong?
Thanks!

Before a new item is considered attached to a branch in git, you must commit it. Git works with commits. Branches (and Tags) are only "pointers" to that commits (or "named" commits).

It suggest that you did not change the branch. You worked on the master branch only. You need to switch to a specific branch by going to Git perspective -> Switch To option.

Related

How can I work on one java project and push my code to multiple git branches as I progress?

I am currently doing a project for a bootcamp and I'm having some trouble. I need to demonstrate that I can use githhub. They want to see that I separate my crud functions onto different branches. So I created a repo using git bash, created a dev branch, with 4 branches coming off of that; create, read, update, delete. I checked out onto the create branch and pushed my create method coding to the create branch. I checked out to the read branch to push my read method code and the files disappeared from eclipse when I checked out to the read branch.
Do I need to push to the create branch and then pull to the read branch to continue working on my read methods?
Hope this makes sense to anyone reading
git checkout create
git add .
git commit -m
git push (gave me an error, prompted me to push upstream?)
git checkout read
// this is where my file disappeared from the package explorer in eclipse.
// my code was successfully pushed to github but I cant continue working on it when I checkout to the read branch
// my next step is to write my read functions, checkout to the read branch and push my code to the branch
I think the way they're wanting to see this done would be to
pull the code
git checkout -b [feature branch name]
Make your partial edits, commit and push
switch back to your base branch, git checkout [root branch]
Repeat at step 2 with you next set of edits.
Then issue pull requests to your root branch for your feature branches.

What happens if you create a git feature branch instead of release branch from a tag?

I created a feature branch instead of release branch from a tag(2.4.1). It triggered auto release and did something, plus created a new tag 2.4.2. The confusion is which tag pointing to the latest version of dev? Is there a way to undo what I did? For which tag should I create a release branch to auto-deploy it?
Nothing happens actually when you just create feature/release branches except that Git just pulls the code accordingly. If anything triggered a build, you must probably be talking about some CI/CD pipeline your DevOps team had set up. I would suggest creating a new feature branch from your previous tag(2.4.1) and start working. You can refer this for Git branching strategy and this for understanding CI/CD.

Merge unrelated repos with multiple branch causing conflicts

So basically I'm trying to go mono-repo.
I followed some nice instructions. The basic idea is:
Create a new git repo.
Use git filter-branch --tree-filter to move the original repo into a subdirectory.
Use git merge --allow-unrelated to merge into the new repo.
It works great with master branch. But ... I'd like to retain history for another branch foo.
So I modify the script like this:
Add -- --all to git filter-branch to do renaming on all logs.
Add git merge from foo to foo into the new repo.
This actually works for some simple repo. But for repo that has a bit of changes in it, it doesn't work for foo and causes merge conflict.
Perhaps I understood the principle behind this wrongly. I was not expecting a merge conflict because there simply was nothing on branch foo in the new repo.
What did I do wrong? Is it possible to go mono-repo and retain history across different branches?

Intellij Idea, Git : Revert commit mechanism not working

I am working on managing our project through GIT. I have Intellij Idea and Git running. The git project is running on one of our servers, which are we connecting through ssh.
Currently, everything is working fine except reverting commits. Somehow the reverts are either failing or not changing anything.
For reverting any last commit, I am going in VCS-->Git-->Reset head(Hard), but it is not helping. Before doing that I have pushed commit to master and I am currently(always) working on master. Is that a problem and is that causing revert to not function.
Now, as you can see in the screenshot below, the last commit named Test1234 is responsible for removing a simple System.out and I am trying to revert it commit Test123, which adds a System.out. What am I doing wrong?
Output of git status :
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
The commits in GitGraken :
I don't know which information related to git to post. Kindly let me know if anything is required.
Try right click to the previous commit in IntelliJ and choose reset current branch to here
When I activate this plugin right it works as the previous image
Perhaps try github's commandline, you'd be able to identify the problem. I also had problems, github's commandline is much better and works faster (especially for reverting / deleting commits).
See http://christoph.ruegg.name/blog/git-howto-revert-a-commit-already-pushed-to-a-remote-reposit.html as reference

Git in netbeans - resolving conflicts

I am using Git in netbeans and I wanted to commit my changes, however first I did a pull, and now there are conflicts.
On the left, I have a .java class that is in red because of conflicts, and I've right clicked it and selected Resolve Conflicts, and went through those steps.
But it still won't let me commit. I would like to override the current HEAD revision with my code, however it won't let me commit. How do I do this?
And when I select the file and choose to see Git -> Diff, it only lets me replace or delete the code in my working copy with the code from the HEAD, rather than replace the code in the HEAD.
Basically, I want to commit my code, not revert, etc. How do I do this in netbeans? It keeps telling me I cannot commit because of conflicts.
I just solved my issue, hope it helps.
1) Updated to Netbeans 7.1.2 IDE, restarted new IDE.
2) Open Git Repository Browser (used a (no branch) local branch) and switch to the branch with the issues both under the Team menu (it will be marked as a no-branch by default, check for the long "Md5 sum" to be the same).
3) Pull other needed code from other branches (in case its needed, I had to in my case).
4) Now edit/paste the code you want to overwritte. (This will turn the filename to red font).
5) Simply right click the file, Git>Resolve Conflicts (and it will do its magic and turn the filename to blue font).
6) Commit your local branch and finish.

Categories

Resources