Sunday, March 21, 2021

Git Commands

"git reset --mixed" This command is used to ignore all the files and merge automatically. and this command resolve repeated conflict errors.

If Conflict Occured Resolving Methods:

step1: Edit that file and reslove the conflict

step2: git add that file

stpe3: git checkout that file name

stpe4: git fetch

stpe5: git stash

stpe6: git rebase origin/master

stpe7: git stash pop

**********************************************************

Latest Methods like featute branch, dev branch, master branch

Step1: create feature branch and shift to that branch

git checkout -b feature/MyFeatureBranchName

To know which branch you are in currently => git branch

Step2: Manually Shift to the feature branch

git checkout feature/MyFeatureBranchName

Step3: pull or get the latest code from dev or master branch

git pull origin dev or master

Step4: After the changes, If we want to commit any thing from feature branch below syntax used

git status

git add 

git commit -m "comments"

git push origin feature/MyFeatureBranchName

Step5: To Know all branches in your local => git branch -a

Step6: If  we want to merge the code from feature branch to dev or master branch. we need to create pull request and merge it.

************************************************

How to pull some_one_worked_feature_branch into localhost

In development where all feature branches we are merging please shift to that branch in localhost for example "dev" branch

git pull origin feature/some_one_worked_feature_branch

git checkout feature/some_one_worked_feature_branch

************************************************

If any error while pull the code from bitbucket

Example:

Step1:

$ git pull

remote: Counting objects: 8, done.

remote: Compressing objects: 100% (8/8), done.

remote: Total 8 (delta 5), reused 0 (delta 0)

Unpacking objects: 100% (8/8), 911 bytes | 1024 bytes/s, done.

From https://bitbucket.org/mfcwl_ibb/mf_lms_web_live

   e3712f8..b453cc3  dev               -> origin/dev

   a2e086d..51f5ce5  feature/bugfixing -> origin/feature/bugfixing

   4b0ee4a..74e45de  master            -> origin/master

error: The following untracked working tree files would be removed by merge:

        uploads/admin/incentive_bulk_upload/922663739ec1e71cd94730ef2721103d.xlsx

        uploads/admin/incentive_bulk_upload/acff049d9334904ce4e4e27abeaa1826.txt

        uploads/admin/incentive_bulk_upload/test.txt

Please move or remove them before you merge.

Aborting

Updating 11bff5d..b453cc3

Step2:

Removing wrongly commited files:

git rm -f uploads/admin/incentive_bulk_upload/*

Step3:

$ git commit -m "removing unwanted files"

Step4:

$ git pull

Step5:  After git pull success add your changes and commit and push to bitbucket

************************************************

If you directly edited server files and want to merge those files with latest update. To avoid conflict and merge or override the files follow the below 3 commands

git pull origin dev
git stash
git pull origin dev

Example: Commit the files to bitbucket and then pull the code to server

root@ip-000-00-00-00:/var/www/html/projectname# git pull origin dev
Password for 'https://testuser@bitbucket.org':
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From https://bitbucket.org/mfcwl_ibb/projectname
 * branch            dev        -> FETCH_HEAD
   7c467bc..f48c083  dev        -> origin/dev
Updating 7c467bc..f48c083
error: Your local changes to the following files would be overwritten by merge:
        .env
Please, commit your changes or stash them before you can merge.
Aborting
root@ip-000-00-00-00:/var/www/html/mmfsl_dealer_api# git stash
Saved working directory and index state WIP on dev: 7c467bc boxop and m2all encryption decryption issue fixing
HEAD is now at 7c467bc boxop and m2all encryption decryption issue fixing
root@ip-000-00-00-00:/var/www/html/projectname# git pull origin dev
Password for 'https://preejanp@bitbucket.org':
From https://bitbucket.org/mfcwl_ibb/mmfsl_dealer_api
 * branch            dev        -> FETCH_HEAD
Updating 7c467bc..f48c083
Fast-forward
 .env | 2 ++
 1 file changed, 2 insertions(+)

Or best and safe method:

Example: Commit the files to bitbucket and then pull the code to server

git stash (Ignore local changes)

git pull origin dev(Pull latest changes)

git stash apply(Keep local old changes)


Or please try this it will work:

git fetch --all
git reset --hard origin/{your branch name dev or master}

This worked for me, May be helpful for other.

*****************************************************
                                Conflict Resolved Technique

From feature branch to dev branch code merging that time if any conflict comes
just follow these steps in localhost:

Step1:
git checkout dev (While switching if any error comes like commit your changes, you can do git add, commit .etc. or git stash)

Step2:
git pull origin featureBranchName

Step3: In your dev branch have conflict resolve and save then
git add that conflict resolved file

Step4:
git commit -m "conflict resolved"

Step5:
git push origin dev

All Done Success.

How to rename the branch name in git:

git branch -m feature/old-branch-name feature/new-branch-name

How to delete local branch in git:

$ git branch -D feature/brabchName

Deleted branch feature/brabchName (was 13155fb).


How to delete remote branch in git:

$ git push origin --delete feature/brabchName

To https://bitbucket.org/repositoryName.git
 - [deleted]         feature/brabchName