GIT Overwrite Master with branch

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 --strategy=ours)

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

GIT SSL certificate problem: unable to get local issuer certificate

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

  1. Open the github you are trying to access in the browser
  2. Press on the lock icon in the address bar > click on ‘certicicate’
  3. Go to ‘Certification Path’ tab > select the top most node in the heirarchy of certifcates > click on ‘view certificate’
  4. 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

  1. Now open the certicate you saved in the notepad and copy the content along with –Begin Certificate– and –end certificate–
  2. To find the path were all the certificates are stored for your git, execute the following command in cmd.git config –list
  3. Check for the key ‘http.sslcainfo’, the correspondig value will be path.
  4. 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.

  1. 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.
  2. 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

Reset a single file to a specific commit

Assuming the hash of the commit you want is c5f567:

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 c5f567, append ~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).

Git workflow

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:
git branch
(your base branch, most likely develop or master. Consider develop as a base branch)
Fetch latest remote code to local:
git pull
(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)
bug branch

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
git push
(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 update and publish

git remote -v
git remote show
git remote add
git fetch
git fetch --all
git pull | git pull
git push
git push
git push origin :old-name new-name
git push origin -u new-name
git branch -dr
git push origin YourTagVersion

Git local changes

git status
Changes files in your working directory
git diff
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
git commit -m 'Commit description'
git commit -a
git commit --amend
git commit --amend -m "an updated commit message"
git commit --amend --no-edit