Why my way to update local files with Github is not working? - github

First I have a master branch in my remote repo on the internet. And I know if I changed my local files, how to update my local changes to the remote repo. Now the problem is, if I don't want my new changes in my local tracked files, how to return back using updating from the remote repo in github?
I have tried the following things:
I use
git checkout origin master
to get to master repo.
I make sure that one tracked file, named main_32.f90 is changed a little bit in the comment line.
Then I use
git pull
it turns out that everything is up to date.
Already up-to-date.
I then checked the main_32.f90, it is not the original one but the changed one in comment line. So it means that the git pull is not working.
So how to do it?

If you don't want to keep your local changes, you can do a hard reset to a pointer, branch, sha1, etc to discard all changes. git reset --hard HEAD.
Use this kind of aliases to have a pretty view of your working tree if you are a console fan and don't want to use any GUI as suggested by other users.

Related

How to push without accepting changes to github

What command do I use to push my code to github through VSCode command line? It is making me pull first, but I don't want to accept any incoming changes.
Maybe that's happening because your current branch (assuming it is main or master) is outdated and wants to update itself first.
There are some ways you can do this:
Using Git in the command line (recommended, easiest way).
Using Visual Studio Code UI.
Using Git in the command line
Say, the current branch you're working on is named updates.
We can use the following command to push to GitHub:
git push origin updates:updates
That will push your changes remotely (GitHub).
You might wonder why updates:updates:
The first one is the name of the local branch, the second one is the name of the remote branch.
After that, your changes will be pushed to GitHub in the branch updates.
If your branch isn't available remotely yet, it will create a new branch named updates with the same commits and changes in the local branch updates. 🙂
Using Visual Studio Code UI
First make sure you're on the correct local branch. You can change branches by clicking on the name of the current branch you're on on the bottom at the left.
Next, go to the Source Control (Ctrl+Shift+G), then click on the ..., then Push.
Your changes will be pushed to GitHub now with the same local branch name.
Hope this answer is useful to you. 🙂

How to recover replaced files in local Git repository after pull request?

Originally on my Github are some outdated styles.css and JavaScript files and others.
I was working on my project last night but didn't push it to Github or back it up. It was just saved in my local repository using a series of local, unpushed commits.
Being a newbie that I am, I did a git pull request master, and all the files in my local repository got replaced with the original styles.css and JavaScript that was in my github.
Is there a way to get those files back?
I did a git reset head#{2} where I believe the state of the repository before the pull request was, and it showed some unstaged files.
In Gitshell my command line has "master [+10 ~19 -42 !]" with the text master being yellow.
At this point, what do I do? Currently I seem to have lost a lot of work.
If you have performed commits often you can pretty much get to any of them.
Use git reflog first (https://git-scm.com/docs/git-reflog). It will show you all the interim commits you've made. Once you find a relevant one you can do git reset #commit_id.

How to get code from Github but don't want to commit from local?

How to get code from github using github desktop for windows?
I want to get latest code everytime from live repostiory as everyone commit there changes and it should be lock with my local changes. I mean I don't want to commit my local changes to live repository.
How to setup this thing?
Thank You.
If I understand you correctly, you want to be able to get updates to your Git project, but you want to leave your local branches alone.
A git pull is out of the question. A git pull is a fetch to update your remote branches, plus a merge to update your locals. Instead, only use git fetch. This will update only your remote branches (ie. your copy of the Github repository), but leave all your local branches alone.

How can I retrieve the local changed files which I wrongly reset in git

Below is the situation which explains what's the matter about git.
I was using the 'develop' branch and already made several changes to the local files such as .sql, .java, .js...
I made a local branch called 'develop_some_future' since my boss wants to confirm my changes before merging main 'develop' repository.
Apparently my local file changes #'develop' branch have applied to 'develop_some_future' branch and I started editing local files again.
For some reason, I tried to pull the files that my co-workers already committed, but it has failed(Probably I couldn't set 'develop_some_future' branch well). So, I changed current branch to 'develop' branch and tried to pull them.
Fortunately it got worked, and then I tried to back to the 'develop_some_future' branch.
A dialog pops up suddenly while changing the branch and asked me that 'your local change for "~~~.sql" would be deleted since it's not committed yet. To avoid this, please commit that file or choose reset.'
Because I thought only '~~~.sql' would be changed to the latest committed state and that was not a problem, I selected 'reset' button, but unfortunately all local changes have gone.
Anyone knows how can I retrieve the date before reset?
I found that both 'git reflog' and 'git reset HEAD{}' commands are useful.
However, git reflog shows only commit, merge, and checkout changes and so I can't find reset status at all.
I'm afraid your files are gone for good, unless you had previously staged the file somehow (add or stash save).
If it had been staged, a blob object was created by Git which is now dangling (git fsck will tell you dangling objects). You can then resurrect the file by writing the blob's content with git cat-file to a new file.
If not, your'e screwed, and you have to do your work again.
It seems the problem arose in the first place, because you thought that unstaged/uncommitted changes belong to the current branch. They do not, and only live in the working directory. They will be carried over when switching branches (unless, of course, the same file was modified in the branch. Git will then refuse to checkout the other branch).

EGit Commit to Remote Branch without Local Branch

I had a branch I was working on for a long time on my desktop. First I commit changes to my desktop's local branch, then push them to the remote branch and everything is dandy.
This morning, I was working on my laptop and selected the remote branch to change. The image below shows what my EGit repository window looked like on my laptop, except there was no local "MethodMigration" branch (there was a local master though). The remote "MethodMigration" branch had the little black check-mark next to it telling me that I'm viewing it as shown in the picture.
https://docs.google.com/file/d/0B7yGmb99B5enZm5OcTcydnEwLUE/edit (Sorry for the ghetto google drive link. I couldn't figure out how to get an image link)
Anyhow, I started adding a whole bunch of stuff. After I was done, I did a "Team->Commit->Commit & Push" after giving it a message. At that point, I remembered that I hadn't made a local branch for it yet... It told me "Nothing to push" even though a whole bunch of stuff had just been specified (which kind of makes sense since I never cloned the remote branch to make a local copy in the first place). The bad part is that all of my code was reverted back to the original "MethodMigration" remote branch code. Additionally, BitBucket shows no commits or anything.
Where did all my changed code go? Is there a way to get it back?
No worries!
You can use git reflog to find the commit id SHA of the lost commit. After that simply merge it with your local branch:
git merge <commit-id>