Your branch and 'origin/dev' have diverged, and have 9 and 8 different commits each, respectively. (use "git pull" if you want to integrate the remote branch with yours) | Merge your local current with remote origin/dev branch
Use command git merge origin/dev & resolve conflicts manually. If already have commited to your branch earlier then try pushing current changes as well & then take latest again.
! [rejected] head -> '' (non-fast-forward)
error: failed to push some refs to ''
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. If you want to integrate the remote changes,
hint: use 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Solution: git pull origin {remote counterpart} not from which this is branched out e.g. origin/dev
git gc --prune=now - Get error/warnings like: error: cannot lock ref etc...
Directly clone from specific branch from remote repo: this will create direct branch locally, make sure to at remote repo only
git clone -b <branch-name> <repository-url>
git branch -avv => shows For all branches
git branch -lvv => For local branches only.
- Preserve local changes using ->
git stash - temporary branch, or
- commit.
git rebase origin/main
-
Before deciding whether to push or undo the commit, you may want to review the differences between your local branch and the remote branch
git diff origin/maingit reset --soft HEAD~1=> Soft reset (keeps changes staged, resets the branch to the previous commit but keeps your changes staged)git reset HEAD~1=> Mixed reset (keeps changes but unstaged, resets the branch to the previous commit and unstages the changes)git reset --hard HEAD~1=> Hard reset (discards changes, resets the branch to the previous commit and discards all changes)
-
git fetch --all -
git merge master- (on branch development), (resolve any merge conflicts if there are anygit checkout mastergit merge development(there won't be any conflicts now) | git merge --no-ff development {merge creates a commit by default}
git cherry-pick This command allows you to apply specific commits from one branch to another. Only your changes from the dev branch to the main branch, you can use the.
- Identify your commits: First, find the commit hashes of your changes in the dev branch.
- Switch to the main branch:
git checkout main - Pull the latest changes from the remote main branch to ensure your local main branch is up-to-date:
git pull origin main - Cherry-pick your commits: Apply your specific commits to the main branch using their commit hashes:
git cherry-pick <commit_hash1> <commit_hash2> ... - Resolve any conflicts if they arise during the cherry-pick process. After resolving conflicts, add the resolved files:
git add <resolved_file>git cherry-pick --continue - Push the changes to the remote main branch:
git push origin main
Example
Start the cherry-pick:git cherry-pick d6f0fb
Resolve conflicts: git add <resolved-file>
Continue the cherry-pick: git cherry-pick --continue
If you want to abort the cherry-pick: git cherry-pick --abort
Git hooks are scripts that can be executed automatically during various Git events, such as pre-commit, pre-push, or post-checkout.
- IS ISSUE IN GIT?: If we rebase current branch (current changes) with origin/main, for whihch PR was already raised and merged, then current changes also gets commited automatically without PR
- Should we keep different local clone for diffent remote origin ???