hilda_sonica_vish
hilda_sonica_vish

Reputation: 757

Git causing confusion

I have some Git-related doubt.

I have done some changes from master branch and by mistake I have commited to master branch. I did:

git add.
git commit "my changed"

But I could not push to the master branch due to some issues. So I have created another branch and from that branch I did push. But I was getting conflicts.

So my doubts are:

  1. If I created a new branch again from master whether I will have all committed changes from the master?

  2. What step do I need to follow to fix this conflict?

  3. What do I need to do to make my master branch as same as server?

  4. If I clone the project again, will it have my committed changes or same as server?

Can I do like? Clone again the master, checkout to the branch I got conflict, do:

git merge master

From there and fix the conflicts?

Upvotes: 0

Views: 78

Answers (2)

Hemant
Hemant

Reputation: 11

  1. Just hit git log to find if you have all commits from master if your HEAD is ahead or at same level as master which means you have all commits from master (or) If you have created a branch from master
    git checkout master
    git checkout -b new-branch
    then YES.

  2. When you have conflicts you have to resolve using
    git mergetool
    Check git status whether you have resolved your conflicts

  3. If you want to get local master reset to remote master branch
    git checkout -B master origin/master

  4. If you had pushed the commit on other branch instead of master, it will be on the remote other branch not on origin/master. So when you are pushing new changes to remote custom branch, git fetch origin master
    git checkout custom-branch
    git rebase -i origin/master
    git commit -m 'Your new feature stuff'
    git push origin custom-branch
    This will only push to remote custom-branch not to master. Create a merge request for merging to remote master.

Upvotes: 1

Pankaj Gadge
Pankaj Gadge

Reputation: 2814

  1. If i created a new branch again from master whether i will have all committed changes from the master?

Yes

  1. What step i need to follow to fix this conflict?

EIther rebase/merge your branch withh/into master and resolve the conflicts using

git rebase origin/master 
git merge origin/master
  1. What i need to do to make my master branch as same as server?

Reset the branch with master using

git reset --hard origin/master
  1. if i clone the project again , will it have my commiitted changes or same as server?

Yes

To conclude, in order to resolve your problems on the branch currently, you should do the following

git checkout branchA
git merge origin/master // resolve conflicts here
git commit
git push

Upvotes: 0

Related Questions