Menu

Showing posts with label Git. Show all posts
Showing posts with label Git. Show all posts

How to clone a git repo with a new name

We can clone any Git repo with new name by specifying folder or directory name while doing the clone. 

The command will look like this.


Command to clone a Git repo with a new name

    git clone <repourl> <folder name>

After the git base url specify the folder or directory name. It will create a new folder with that name and clone into that.


Remove or delete a Git subtree

There are multiple ways to add and remove the subtree in Git repo.

  1. git rm -rf plugins/experimentation
  2. git rm -rf gitpath

git command to discard/reset a file changes

When we make some change in an existing file, but that change doesnt go for commit, in this situation we have to reset the file with the last commit or undo the file changes. For undo and reset a file in git use this got command.

git command to reset a file: git checkout <file path /filename>

git error fatal: cannot create directory because filename too long

A too long file name is an issue while cloing any git repo. We can set a git property longpaths=true to allow the too long file name for git. Following the command and their scope.

  1. For all users

    git config --system core.longpaths true
  2. For current user

    git config --global core.longpaths true
  3. Only for current clone

    git clone -c core.longpaths=true

Direct integration of cloud manager in your git repository

Would you like to move from adobe managed git in cloud manager to self managed git repository? Adobe cloud manager is now running program where we could directly integrate any git repository to cloud manager. When you will open cloud manager, it will ask to opt this feature with a request form. 

You will see below form in cloud manager to opt the feature of using direct git repo.


References

https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/implementing/using-cloud-manager/managing-code/integrating-with-git.html

fatal: unable to access 'https://jorvee.bitbucket.com/branch/src/': SSL certificate problem: unable to get local issuer certificate

Error: 

fatal: unable to access 'https://jorvee.bitbucket.com/branch/src/': SSL certificate problem: unable to get local issuer certificate

Resolution: 

There is a workaround to disable the ssl and bypass the check. Use the below command to overcome from this error. 

For only current repository

git config http.sslVerify false

For disable the ssl at global level 

git config --global http.sslVerify false


Now you can run your git commands without any trouble. Thank you! 

fatal: refusing to merge unrelated histories

While merge the two different branches one could face this issue when both the branches are not created with same parent or base branch. If still there is a need to merge or pull the code from another branch, then use the --allow-unrelated-histories with git pull command. This will ignore the histories error and forcefully pull the code from another branch.

e.g.

 git pull origin feature-new-git --allow-unrelated-histories


Resolve code merge conflicts

In this blog post, we are going to learn to resolve the conflicts with merge requests or pull requests in Git codebase. 

Let's assume we have two branches and trying to merging code from develop branch to master branch. 

Git merge conflicts | Atlassian

Source branch: develop

Destination branch: master

Step1: Open Git bash and check out the latest source branch code in local directory. e.g. git checkout develop This Git command will pull the latest code from develop branch in the local repo and this will change the current working branch to develop in Git Bash. 

Step2: Now we need to pull the code of the destination branch into the source branch. Hence in our case, we will run Git command git pull origin master. This command will pull the code from the destination and match it with the source. This will also show you a list of all the files where conflict needs to be resolve to successfully merge. 

Example: 

Auto-merging src/header.java
CONFLICT (content): Merge conflict in src/header.java
Automatic merge failed; fix conflicts and then commit the result.

Step3: Now open your developer IDE and look for above mentioned file [src/header.java], and see where the conflict is. IDE by default also gives some hint to accept the source changes or destination changes, you may just click on that option and keep and go only with one change. If you think that option is not sufficed your need and you have to manually make some changes in code then go ahead and make the required changes and save the changes.

Step4: Since we have fixed the code changes, now it is time to check-in the code into the source branch. To check-in the code uses the below commands in Git one by one.

git add <file name> or .(dot) if we wants to add all the files.

git commit -m "commit message"

git push origin develop


Step5: Now go to merge request and see, the conflicts will be get resolved. And now we could merge the code.

 

Reference:

Bitbucket merge conflict

How to fetch and checkout a git branch?

Git is a version control system that is used to store and manage the codebase. A branch from Git can be checkout using Git command > git checkout <branch_name>.

A new branch can be fetch and checkout using below git command.

git fetch && git checkout feature/social_sign


Git version control for programmer

 

How to force git pull to overwrite local file changes?

 


git reset --hard HEAD

or 

git reset --hard origin/<branch name>


After that take a pull using git pull command to pull all new commits.

Git diff is showing complete file content as changed but there is only few line of changes in file.

This is expected behavior of Git diff and there is nothing wrong in this case. See the issue 52036
When we look the plain diff, we can see that, the old content used Windows style line endings (CR LF), whereas the new content is stored with Unix style line endings (LF).
>> old style.scss file content
Line 1 CR LF
Line 2 CR LF 
>> new style.scss file content
Line 1 LF
Line 2 LF 
We may skip those white space changes from compression using GitLab or Git via UI or command line. 
Steps to hide/ignore white space changes from git diff.
  1. Go to your merge request.
  2. Navigate to change between section.
  3. Click on the setting button, from right side of "change between section"
  4. Unchecked the option "Show whitespace changes"
After doing this you the compare section will show only real changes. Below is the screenshot which you refer.
Show-whitespace-changes-git-diff


We can also see the exact diff using ignore space command
git diff --ignore-space-at-eol

References

How to delete commits from a branch in Git?

Checkout the branch. e.g we are working here with development branch
$ git checkout development

Go to the commits list and copy the commit id till where you want to remove the commits from branch. then run git reset --hard to delete the all commits above or after that commit id. e.g. commit id is "c9709eb155e18e2eb12e38bf
$ git reset --hard c9709eb155e18e2eb12e38bf

You will got a success message saying "HEAD is now at <commitid> <commit message>". It means your reset is successful.

Now run the git push to push the commit till this commit id to your branch.
$ git push origin development --force


Related Articles:

How to cherry pick in Git 

How to cherry pick multiple commits from a branch to other?

It is very common practice to pull push and merge the changes from one branch to other branch for developer. Today we are going to see how we could cherry pick changes from one branch to other branch or from feature or working branch to master. Some times we come at a situation where we do not want to merge the complete branch into another branch, instead of complete merge or pull we just want to merge few commits from one branch to another, for that we have cherry pick option in git.

for example we are currently working on branch feature/fix01, and n commits are available on fix01 branch.
Now we want to cherry pick only commit A and B to master branch. to do so, please do the following steps.

Step 1: Open git bash.
git checkout fix01
git log
 $git log command will show all commits, with commit details. From here you can take the commit ID. Alternate to get the commit ID is from git UI, check for the commit SHA. As shown in below screenshot.

 
Step 2: Now checkout the master branch where we need to push the commits.
git checkout master
Step 3: Now run the cherry pick command
git cherry-pick a001 b001 // here a001 and b001 is commit IDs for A and B commit respectively.
if cherry-pick command didn't run successfully and halted due to some conflict, then go to repo and fix the conflicts and then came back to git bash and run the cherry-pick continue command.
git cherry-pick --continue

if you want to stop the cherry-pick or end the process, then run cherry-pick abort command.
git cherry-pick --abort

Step 4: If you cherry-pick was successful then run the git push to move the commits.
git push origin master/master
Step 5: Verify the changes.

References: