Commands to set global and local email-id:
git config --global user.email ayan.pal@thoughtworks.com
git config --local user.email ayan.pal@thoughtworks.com
Commands to tag
git tag -n
git tag -s v2.1.1 5d8e2d5d80f -m "added tag for prod release on 30nov2021"
git push origin v2.1.1
Commands to reset code:
git reset --hard
git clean -fd
git pull
git checkout -- .
echo 'Spotting the differences........'
git diff HEAD --name-only
Command to ignore pre-commit hook while pushing:
git push --no-verify
git push --force --no-verify
Commands to rollback to a specific commit:
git reset --hard <commit_id>
git push origin HEAD:master --force --no-verify
Commands to delete branch from local if already deleted from remote:
git fetch -p
Command edit last commit:
git commit -S amend
Commands to resolve merge conflicts:
This pull request has conflicts.
You must resolve the conflicts by manually merging feature/PERFFLOW-1584-expo9-release into this branch. After the conflicts are resolved you will be able to merge the pull request.
Step 1: git branch -a
Step 2: Checkout the source branch and merge in the changes from the target branch. Resolve conflicts.
git checkout feature/PERFFLOW-1568-cleanup-tf_pixel_url_mapping
git pull origin feature/PERFFLOW-1584-expo9-release
Step 3: After the merge conflicts are resolved, stage the changes accordingly, commit the changes and push.
git commit
git push origin HEAD
Step 4: Merge the updated pull request.
How to push in 2 git repo together?
--run the following command to see the remote-repo urls
>>>> git remote -v
origin git@sgts.gitlab-dedicated.com:wog/hpb/phdh/hpb-phdh/infra.git (fetch)
origin git@sgts.gitlab-dedicated.com:wog/hpb/phdh/hpb-phdh/infra.git (push)
# also can create a new remote repo like this: git remote add both ssh://git@bitbucket-ssh.ship.gov.sg:7999/hpbphdh/phdh-infra.git
# can add 2 repos in this newly created alias as well:
# git remote set-url --add --push both git@sgts.gitlab-dedicated.com:wog/hpb/phdh/hpb-phdh/infra.git
# git remote set-url --add --push both ssh://git@bitbucket-ssh.ship.gov.sg:7999/hpbphdh/phdh-infra.git
--add 2 remote repos in the alias "origin", after this "git push" will push in both destinations
git remote set-url --add --push origin git@sgts.gitlab-dedicated.com:wog/hpb/phdh/hpb-phdh/infra.git
git remote set-url --add --push origin ssh://git@bitbucket-ssh.ship.gov.sg:7999/hpbphdh/phdh-infra.git
--How to push in 2 git repo together (detailed example for ttp-service repo, applicablw to other repos as well) ?
--1) Checkout latest code from Bitbucket in the working-directory (https://bitbucket.ship.gov.sg/projects/HPBPHDH/repos/ttp-service/browse)
--2) Checkout latest code from Gitlab in a different directory, lets say in "gitlab-directory" (https://sgts.gitlab-dedicated.com/wog/hpb/phdh/hpb-phdh/ttp-gcc-service)
--3) Go inside the working-directory, and run the following commands (change GPG key according to the "xxxxxx@thoughtworks.com" email, as by default Bitbucket works with "xxxxxx@techpass.gov.sg" email which is not supported by Gitlab -- but Bitbucket can still support both emails !):
--a) gpg --list-secret-keys --keyid-format LONG # note GPG Key ID for "xxxxxx@thoughtworks.com" email -- it will be the 16 character key after the "/" (something like ed25519/XXXXYYYYZZZZKKKK)
--b) git config user.signingkey <GPG Key ID for "xxxxxx@thoughtworks.com" email>
--c) git config --global gpg.program gpg
--d) git config user.email "xxxxxx@thoughtworks.com"
--8) Make any small change (like adding one empty line in ".gitignore" file) and push (it will be by default pushed in Bitbucket)
--9) Replace the ".git" folder in the working-derectory with ".git" folder from gitlab-directory.
--10) Again run the following commands to set the GPG key and User-email (as working-directory's metadata got changed to point to the Gitlab repo):
--a) gpg --list-secret-keys --keyid-format LONG # note GPG Key ID for "xxxxxx@thoughtworks.com" email -- it will be the 16 character key after the "/" (something like ed25519/XXXXYYYYZZZZKKKK)
--b) git config user.signingkey <GPG Key ID for "xxxxxx@thoughtworks.com" email>
--c) git config --global gpg.program gpg
--d) git config user.email "xxxxxx@thoughtworks.com"
--11) Run command in working-direcrory: "git status", and note the differences.
--12) Add all these differences and push (it will be pushed by default to Gitlab repo now)
--13) Now at this point, both Bitbucket and Gitlab repos have the same codebase, though their respective HEA-commit IDs are different. Thus, we'll now have to by force equate there HEAD-commit ID Hence run the following commands in the working-directory:
--a) git remote add bit ssh://git@bitbucket-ssh.ship.gov.sg:7999/hpbphdh/ttp-service.git
--b) git remote set-url --add --push origin git@sgts.gitlab-dedicated.com:wog/hpb/phdh/hpb-phdh/ttp-gcc-service.git
--c) git remote set-url --add --push origin ssh://git@bitbucket-ssh.ship.gov.sg:7999/hpbphdh/ttp-service.git
--14) Add another small change in code (like removing the previously added ampty line from ".gitignore" file)
--15) Add this change by the following command: "git add .gitingore"
--16) Run: "git push --force"
--17) Now, both Bitbucket and Gitlab repos should have the identical HEAD-commit Ids. Check if by going to the respective repos from your browser.
--a) Bitbucket: https://bitbucket.ship.gov.sg/projects/HPBPHDH/repos/ttp-service/browse
--b) Gitlab: https://sgts.gitlab-dedicated.com/wog/hpb/phdh/hpb-phdh/ttp-gcc-service
--18) Also, remember to pull changes from bothe repos together always by the following command: "git fetch --all"
--19) Kindly perform the above-mentioned steps for all the codebases untill we completely migrate everything from Bitbucket to Gitlab (like PHDH-Infra, Orchestrator, PHDH-Processor etc).
https://stackoverflow.com/questions/11646107/you-have-not-concluded-your-merge-merge-head-exists
https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging
http://nfarina.com/post/9868516270/git-is-simpler
https://stackoverflow.com/questions/8198105/how-does-git-store-files
https://stackoverflow.com/questions/3082445/where-does-git-store-files/3082740#3082740
https://www.linkedin.com/pulse/git-internals-how-works-kaushik-rangadurai
https://www.quora.com/What-does-git-store-internally-only-the-diff-or-the-entire-file
https://gist.github.com/matthewmccullough/2695758
https://blog.thoughtram.io/git/2014/11/18/the-anatomy-of-a-git-commit.html