How to use TortoiseGit to perform the git command `git reset --hard origin/master`? - tortoisegit

I have this scenario when use TortoiseGit.
A use the Reset master to this... to revert some changes and force pushed to the remote refs master.
B pull the code and said Already up-to-date. And use the show log said the local master is before origin/master.
I know using the git command git reset --hard origin/master will fix this for me.
I would like to know how to overidde local master with remote origin/master using TortoiseGit?
Thanks.

You need to switch in the log to remotes/origin/master
All the steps:
Fetch
Switch to master
Go to log
On the left upper side, select remotes/origin/master :
Do reset "master" to this , en then "hard"

Related

The local repository is out of date when push the code even after pull is completed

1.Pull the latest code[
2.Commit the new code
3. When tried to push the code to bitbucket repository getting message "Local repository out of date[![enter image description here]
**
tried bothway Xcode push and cmd based push but no luck still getting this weird message
Note:
Xcode 12.4,
bit bucket
I don't understand, the image shows after the "pull"? If not, please edit your question and place the image in the correct place.
That message can be because someone else have pushed to your repo after the last time you pulled from it. You will need to revert all the X commits that you have done after your last succed push (save the work in another branch or whatever):
git reset --hard HEAD~X
Or reset your local branch to directly match your remote branch:
git reset --hard origin/remote-branch-name
Pull from the repo, make your commits and then you will be able to push again.
You have another option: PULL FORCE!!!
If you alredy known the "push --force" command, then pull force will sound you familiar, but in reality doesn't exist something like "pull --force", but exist a way to replicate that functionality in pull requests:
git fetch --all
git reset --hard origin/master
git pull origin master
(Replace "master" by your branch name)
With that command you overwrite your git history to match exactly the history of your remote repository branch. That will overwrite local changes (the ones that you have not pushed yet) and then you can make your commits and push them.
You can avoid this ackward situation by always working in a new branch only for your work, and when you need to integrate your changes you can make rebase or merge.
There are changes in your local repository that are not on the remote and vice versa, causing a conflict in your history.
You could try the following in your local repository (assuming your remote is called origin):
Make sure your local changes are committed (git commit -am "Some commit message")
Create a new branch (git branch new-branch-name)
Fetch the remote branch (git fetch origin)
Reset the target branch to the version on the remote (git reset --hard origin/target-branch-name)
Merge your newly created branch (git merge new-branch-name)
Push your changes to the remote (git push origin target-branch-name)
Finally resolved it by push the commits to the new PR and then merged the code with old PR

BitBucket - error: failed to push some refs

I have some projects I would like to upload on my bitbucket private profile. I performed the following steps but I get an error.
Convert my project to git with: git init
Next:
git add
git commit -m "some message"
I created a bitbucket repository and version control system is GIT.
I then type this (of course with real account name and reponame and repo owner):
git remote add origin https://<repo_owner>#bitbucket.org/<accountname>/<reponame>.git
Finally,
git push -u origin master
I did all of this and my terminal gives me this error:
To https://bitbucket.org/milosdev_me/lfs.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://milosdev_me#bitbucket.org/milosdev_me/lfs.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Try:
git push origin master --force
This works for me.
Your master branch has some code that you don't locally have, and to prevent you from conflicts, it doesn't let you to push further changes, before you have them locally. To resolve this, pull all the changes to your local repository (your project):
git pull origin master --allow-unrelated-histories
After that, you will have all the code that is available on your master branch.
NOTE: Be careful, pulling the code from remote branch might mess up all the changes locally. Make sure to save those changes somewhere, or create another branch locally where you will pull your origin master branch, so it doesn't mess up your changes.
Your issue is that you have different things between your local repository and your git repository (probably a readme file that you created automatically), so you have two options:
use git pull origin master, with this command, you will pull from your git repository, but it will cause a merge conflict, which you have to resolve using an IDE (recommended to beginners) or through cmd.
use git push origin master --force, this way, you will force your push from your local repository to your git repository, ignoring any merge conflict by overwriting data. I'm not sure, but I think it will overwrite all git repository data with you local repository data (which is what you want).
Adding --force option is a bad idea
Either rebase it or pull the code, merge it and push it.
git pull --rebase origin master
git push -u origin master
Your remote repository and local repository have differences, something new in remote repository. So for pushing you need pull changes, from remote, previously. Try do:
git pull
git push -u origin master
The issue is because your remote repository and local repository have differences.I had same issue and i tried all the above mentioned solution but nothing worked for me.
For me the scenario was :- I already had my branch in remote repository.If you have the same scenario then follow below steps:-
run command 'git pull'
delete branch from local repository
checkout that particular branch using "checkout as a new local branch" from
the Remote repository.
run command 'git branch -u <your_branch_name>'
run command 'git push or git push --force'
or you can try directly from step 4 first , if it does not work then follow entire steps.Hopefully it will help someone.
If you have your bitbucket account linked to jira.
(this answer will work for you, only if you have your jira account linked to bitbucket)
I was having the same problem trying to push my current branch with the origin.
for example:
my branch name was:
feature/PREFIX-000-new-name-branch.
previous commit:
git commit -m "Write your commit here"
so far it was not working.
you have to mentioned the ticket name in the commit.
if you have made the commit, make an --amend to rename your commit and retry it.
git commit --amend -m "PREFIX-000 Write your commit here"
try the push again.
If you are using BitBucket, this issue occured when I tried to push to a branch but that branch has writing disabled via the repository settings.
if you have already created a project locally and you want to upload it to git,
you will then need to do:
git status to see the changes you need to upload
git add . to add those changes to your repo
git commit -m "" to add a commit message
git push origin master
that way I solved the very same problem I
was having.
it might be a configuration issue
I fixed this issue after updating the global user.email value with my email
git config --global user.email my#email.com
Note: You need to delete the previous commit because it had the wrong email in the commit

Unable to update my GitHub from my Mac

Why am I unable to update my GitHub from my Mac?
git status produces the following:
On branch master Changes to be committed: (use "git reset HEAD
<file>..." to unstage)
new file: file.test
Untracked files: (use "git add <file>..." to include in what will be
committed)
.DS_Store
git push produces the following;
fatal: The current branch master has no upstream branch. To push the
current branch and set the remote as upstream, use
git push --set-upstream origin master
You need to git add ., then git commit -m "My commit message", then git push -u origin master.
That will set the upstream to the origin/master. Moving forward, just git push shall suffice
Git works through commits - which are basically snapshots of what your repository looked like at a given point in time. You need to commit the files to your repository before you can actually push them to GitHub.
So your first step is to add the files to the "Staging Area" with
git add file.text # you can do git add . but this will add all files which you may not always want
Now you can check the current status of the "Staging Area" with
git status
This will let you make sure that you are only committing the changes that you want added.
Now you can commit the changes. Committing will only 'save' the files that are in the Staging Area.
git commit -m "A useful description of what you did since your last commit"
Ok so now you're ready to push. Assuming you cloned from GitHub you can just run
git push origin master
But if you created this repository with git init you will need to tell git that you have a remote repository somewhere. Do this by running
git remote add https://github.com/<usernane>/<repo_name> origin
This origin is the name you would like to associate with the remote repository. 'Origin" is the most common but you may have other remotes like "backup" or "code_review" for different use cases.
Once you have added the remote repo, you can actually push to it with
git push origin master
Again, origin is the name for your remote repo and 'master' is a 'branch' name.
You can add the -u flag which will make it so that git assumes you want to push to origin. So in the future you would only need to run
git push
Listen to the error messages. :)
You currently have one untracked file, .DS_Store which I happen to know is a system file, so you may want to add that to your .gitignore
As for trying to push upstream, you need to set your upstream for each branch, so you simply need to type the command
$ git push --set-upstream origin master
then do a simple
$ git push
to send your changes to github.
If the branch you are pushing to online is ahead of you, then you may need to do a git pull to get grab the changes, before you do a git push.

Octopress pushing error to GitHub

I'm trying to push an octopress to github page,everything has worked fine up to now but when i do the rake deploy command after displaying octopress files i get the following error
To git#github.com:rukshn/rukshn.github.io.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git#github.com:rukshn/rukshn.github.io.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
what's the problem?
Since this is the master branch, i.e., the one running your generated pages, you need to drop into the _deploy directory, then do the git pull origin master. Somehow your deploy directory has gotten out of sync. Do you have more than one local repo you write to and deploy from? (Say on different machines...) If you do, then you should always make sure to sync your the sources on the various repos as well.
do
cd _deploy
git reset --hard origin/master
cd ..
and try again
rake generate
rake deploy
Try:
git checkout source
rake gen_deploy
#slavik comment works like a charm.
#Benjamin I think #rksh skipped below steps,
Don't forget to commit the source for your blog.
git add .
git commit -m 'add source code to source branch'
git push origin source
I met the problem and solved it by removing the master branch in the _deploy folder in the source branch. The detailed commands are as follows:
// change directory to _deploy
cd _deploy
// check out local master branch
git checkout master
// rename local master to master2
git branch -m master2
// list of remote branch
git branch -r
// create a new local master branch and tracking remote master branch
git checkout origin/master -b master
// pull the remote master branch, ensure that the local master branch has Already up-to-date.
git pull
// delete the local master2 branch if not needed.
git branch -d master2
```

Git revert local commit

I have a git repo hooked up in phpstorm on windows. I committed a few change sets then pushed them to our "central repo". After this I have then made a few more commits. I no longer want these commits that have not been pushed to the central repo. How do I clean my working copy to be the same as the central repo (origin)?
git reset --hard remotes/origin/HEAD
git reset --hard remotes/origin/YOUR/BRANCH
better than /HEAD because you won't see this:
$ git status
On branch MY/BRANCH
Your branch and 'origin/MY/BRANCH' have diverged,
and have 1 and 1 different commit each, respectively.
You can revert local commit by
git reset HEAD~N
where N is used to revert number of commits. An example:
if you have to revert single commit from local, then you can use
git reset HEAD~1
or
git reset HEAD^
If you feel sure about that and don't have any local uncommitted changes:
git reset --hard origin/master
where origin/master is the branch you had pushed to.
The ref-log will still contain the reverted bits, until a garbage collect expires them. To revert the revert,
git reset --hard HEAD#{1}
As per my understading, you create some commit that you have pushed on central repo, after that you have create some more commit, but these are exist on local. These all did not push on central repo.
To remove/revert local commit;
git reset HEAD~{number_of_commit}
simply, you hit git log on your command prompt and get list of commits. Have a look, how many commit you have created now and how many you have to revert.
for example, you have to remove.revert your two last commit then hit
git reset HEAD~2
There is one another way to reset your local repo with central repo. But, in this case your local commit will be removed and if other users push commit on central repo then your repo will be updated with that.
command is :
git reset --hard remotes/origin/HEAD

Resources