You should be able to use the “ours” merge strategy to overwrite master with develop branch like this:
git checkout develop
git merge -s ours master
git checkout master
git merge develop
The result should be your master is now essentially develop.
-s ours is short for
From the docs about the ‘ours’ strategy:
This resolves any number of heads, but the resulting tree of the merge is always that of the current branch head, effectively ignoring all changes from all other branches. It is meant to be used to supersede old development history of side branches. Note that this is different from the -Xours option to the recursive merge strategy.
Update from comments: If you get fatal:
refusing to merge unrelated histories, then change the second line to this: git
merge --allow-unrelated-histories -s ours master
Solution 1 (worst): disable certificate in GTI configuration
git config --global http.sslCAinfo /bin/curl-ca-bundle.crt
Solution 2: if this problem is occuring because git cannot complete the https handshake with the git server were the repository you are trying to access is present.
Steps to get the certificate from the github server
- Open the github you are trying to access in the browser
- Press on the lock icon in the address bar > click on ‘certicicate’
- Go to ‘Certification Path’ tab > select the top most node in the heirarchy of certifcates > click on ‘view certificate’
- Now click on ‘Details’ and click on ‘Copy to File..’ > Click ‘Next’ > Select ‘Base 64 encoded X509 (.CER)’ > save it to any of your desired path.
Steps to add the certificate to local git certificate store
- Now open the certicate you saved in the notepad and copy the content along with –Begin Certificate– and –end certificate–
- To find the path were all the certificates are stored for your git, execute the following command in cmd.git config –list
- Check for the key ‘http.sslcainfo’, the correspondig value will be path.
- Now open ‘ca-bundle.crt’ present in that path.
Note 1 : open this file administrator mode otherwise you will not be able to save it after update. (Tip – you can use Notepad++ for this purpose)
Note 2 : Before modifying this file please keep a backup elsewhere.
- Now copy the contents of file mentioned in step 1 to the file in step 4 at end file, like how other certificates are placed in ca-bundle.crt.
- Now open a new terminal and now you should be able to perform opertions related to the git server using https.
To know where gitconfig file is:
git config --list --show-origin
Assuming the hash of the commit you want is
git checkout c5f567 -- file1/to/restore file2/to/restore
The git checkout man page gives more information.
If you want to revert to the commit before
~1 (where 1 is the number of commits you want to go back, it can be anything):
git checkout c5f567~1 -- file1/to/restore file2/to/restore
As a side note, I’ve always been uncomfortable with this command because it’s used for both ordinary things (changing between branches) and unusual, destructive things (discarding changes in the working directory).
Here you can see the basics workflow for git
After cloning your repo from any git platform provider Like github, gitlab, bitbucket etc… .
Firstly check branch:
(your base branch, most likely develop or master. Consider develop as a base branch)
Fetch latest remote code to local:
(for latest develop code)
Checkout new branch as per feature and
git checkout -b newBranchName
(If you are working on any new bug named branch feature than give branch name feature/ login-feature or you are working on any bug than give branch name bug/login-bug.
This way you can eaisily identify/judge your branch by name.)
After finish your work in your
$ git status (after Changes )
Add changed file into staging
git add . | | $ git add .. (dot) (for feature/bug branch.(in red colored) add file in staging)
Check staging file (in green colored)
$ git status
Add commit message
$ git commit -m Commit message
Checkout your base branch
$ git checkout develop (switch
For latest code (if other guy
$ git pull (for latest develop code)
Checkout your previous feature/to develop) working on it)
git pull (for latest develop code)
Checkout your previous feature.
git checkout YOUR PREVIOUS_BRANCH
Rebase your branch with develop
git rebase develop
Push your feature/bug branch
(it will suggest command if bug branch or master to remote: its not in remote).
After this open your git platform provider Like github, gitlab, bitbucket whatever you use.
Assign merge request to your other develop to review code, it will increase your productivity and code quality.
git remote -v
git remote show
git remote add
git fetch --all
git pull | git pull
git push origin :old-name new-name
git push origin -u new-name
git branch -dr
git push origin YourTagVersion
git reset --hard HEAD
git reset --soft
git checkout HEAD
git reset --hard
git reset --hard
git reset --keep
git rebase --continue
git rebase --abort
git add | git rm
Changes files in your working directory
Changes to tracked files
git diff <filename|filepath>
Show or list our the changes of specific file as per comparison to previous commit
git add . | git add ..
Add all current changes to the next commit
git add FILENAME
Add particular file changes to the next commit
git add -p
git commit -m 'Commit description'
git commit -a
git commit --amend
git commit --amend -m "an updated commit message"
git commit --amend --no-edit