Github Simple Commit Issue - github

I made modifications to my github repo on the actual website rather than the terminal. Now, I can't commit anything locally from my computer to my terminal because it says the files stored locally are not in sync with the github repo. How can I fix this so I can push my changes in terminal? Can I undo my previous commits that I did on the website?

(Optional) If you've some modifications locally, stash them first:
$ git stash
Because you've made some modifications at remote repo, you need to pull them down before pushing new commits (fix conflicts one by one if you got in this step):
$ git pull origin your_branch
Now your local branch & remote branch are in same stage, get back previously stashed modifications back (if you did step #1 before):
$ git stash pop
$ git add .
$ git commit -m "commit msg here"
It's OK to push local modifications to remote then:
$ git push origin your_branch
Btw, if you did modification at remote repo BY MISTAKE, and just want to use local repo as latest, you can push local repo to overwrite remote one (make sure remote repo's branch is not protected by server):
// !!! Use it wisely & carefully, cause it will overwrite the whole branch at remote side.
//
$ git push -f origin your_branch

Related

Git Push "everything up to date" but file on github not change

after i learn to commit a file to github. now i have try to update file on github
by run syntax
git push -u origin main
and output message
Everything up-to-date
Branch 'main' set up to track remote branch 'main' from 'origin'.
when i check again on github the file that i was push no change at all
here my local file
please help me, im new to github
Have you committed first? With git, you need to commit your changes first, which is like saving each version locally. Then, when you push, you are publishing all of your versions to the remote (github).
Try the following:
git status
if it tells you about untracked files, use:
git add <filepath>
then:
git commit -m "<some commit message>"
This will save your changes as a commit locally, and you can now push this commit to github with the push command you used earlier.

How to delete GitHub blame history?

I'd like to delete the GitHub blame history that GitHub shows (tracking all changes made)
I am aware of how to how to roll back changes, but I am not trying to roll back any changes I have made, I am simply trying to delete this history of the changes.
Obviously, I do own the repository that I will be operating on (and am the sole owner)
If this is for all files of your GitHub repository, the simplest way would be to:
initialize a new local repository
add files from the original repo
add as remote the original repo GitHub URL
force push
That is:
git clone https://github.com/me/myrepo
git init myrepo2
cd repo2
git --work-tree=../myrepo add .
git checkout # -- .
git commit -m "Import myrepo"
git remote add origin https://github.com/me/myrepo
git push --force -u origin master

git(hub) lost all my changes in group project

I am working on an eclipse project with two friends. We use Git(Hub) to work as efficient as possible. Here is the problem: I worked on the project and uploaded the changes. Unfortunately, my friends were not able to see my modifications. Nevertheless, I was still able to see my new version in eclipse. Now I tried to upload it again but "there was nothing to upload".
Then I used git fetch and rebase to see if something would happen.
Unfortunately, all changes are gone now. I used git commit --amend and they "found a swap file by the name xx with the date of my last upload!".
Does anyone know how can I get back to my working version now?
If you didn't push your changes after messed up local history, then reset your local with remote.
$ git branch <branch-name> # backup the branch for safety
$ git fetch # sync with remote
$ git reset --hard origin/<branch-name> # reset local branch with remote branch
Alternate: git reflog will show you the whole git history you executed the commands. Copy the last working commit-hash you want to go back.
$ git reflog
Checkout to that commit.
$ git checkout <commit-hash>
$ git log # see the commit history
If all things are ok. Then checkout to a new branch. If you do any change in new branch then do Add, Commit and Push or, just Push to remote.
$ git checkout -b new-branch # create a new branch called 'new-branch' and checkout to that branch
$ git add .
$ git commit -m 'message'
$ git push origin HEAD # push to remote new-branch

Remote repo says it is up-to-date, but lacks hundreds of local commits

In Eclipse (using Egit) I have my repo set up like this:
I pull from a remote GitHub repo (my lecturer's) at github.com/hallvard/tdt4100-2017
I add files and modify a few of the ones I pull from there. Using Eclipse's egit, I commit changes to my local repo (including all files from the remote pull repo.), and push everything to my own GitHub repo where I then have all of my own files, and my lecturer's files, and my lecturer's modified files.
That repo is at github.com/vegarab/tdt4100
Yesterday something weird happened: When pushing to my own repo., it kept saying the master branch was up-to-date, which it was NOT.
YES I did stage the files, and they were commited to the local repo.
I tried going to terminal and pushing to remote from there, but no luck.
I headed to my GitHub history and found the last commit, and did a:
git reset commitid
I then tried to push to the remote, but it still said it was up-to-date? EH WHAT?
I copied my local repo just to make sure I still had my files if something went wrong:
I did a
git pull -f origin master
and it did some changes: My my remote repo is just a fork of the lecturer's repo. All my files are gone, except they are still there in the local repo. Trying to push them gives yet another up-to-date, except the remote now misses hunders of my own commits, and hundreds of files and folders.
What do???
Make sure you are Pushing to correct repo. Say you have two remote:
upstream: The repo from where you forked your own repository
origin: Your own repository
Clone your own (origin) repo.
$ git clone <own-repo-url>
Do changes, update files, Add, Commit, Push to origin
# do some changes
$ git add .
$ git commit -m 'Add my changes'
$ git push -u origin master
Now assume upstream is updated and you need to take the upstream's new changes and then update own origin repo.
$ git pull upstream master # pull upstream/master changes
$ git push origin master # push the changes to origin/master
I ended up pushing the local backup repo. to the remote one, which "restored" the remote one into the correct state.
I then deleted the original local repo, and created a new one, pulling from my remote repo. I then pulled new changes from lecturer and pushed to my own repo. It is now fixed.

cannot see committed changes in repo

I have staged my files like this
git add mydir
git add mydir/myfile
and then pushed them to my repo
git remote add origin https://github.com/usename/myrepo.git
git push origin master
When I look at git status -s it says my files have been added, but I cannot see them in my actual repository. Does anyone know whats going on here?
You have not "added" your files to the repository, only to the staging index.
You need to git commit to get your changes from the staging index to the repository.
git status shows you the status of the working tree and staging index. git log shows you the status of the history - in other words, git log will show you what's been committed to the repository.
As an example, see this git status output:
git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD ..." to unstage)
#
# modified: Game.py
#
In this case, we can see that the changes to be committed involve Game.py. Note that these changes haven't yet been added to the repository - they're just staged, ready to be committed, as the git status says.
The next step is to commit these changes we've prepared in the staging index and add them to the repository. git commit is the command to do this.
This answer, as well as the linked Pro Git book, have some excellent reading which will help you understand the setup and steps in committing to a git repository.
I cannot see them in my actual repository.
What do you mean by "actual" repository? I am presuming you mean you can't see a local commit, but there may be some confusion about the repositories you're using.
You're using two repositories, one local and one remote. The remote repository is, in your case, on GitHub. You do your work locally, then git push to remote.
First, local changes and commits
So the steps to get your code changes into the local repository are as follows:
Make changes in your working directory. This is most often writing some code.
Build a commit by staging changes. This is done using git add.
"Save" the commit you've built into the repository. This is done using git commit.
These steps take place **locally*. None of these steps have any affect on your GitHub repository.
Secondly, git push to the remote repository (in this case, your GitHub one).
To get your code from local to remote repositories, git push is used.
Check what remote repositories are known by your local repository: git remote -v.
If the GitHub repository is not shown, you'll need to add it: git remote add <NAME> <URL>.
Because you didn't git clone, the two repositories (local and remote) don't have any commits in common. That's ok; it just means git doesn't automatically know where to push your changes, so you'll have to specifiy: git push <NAME> master:master. That'll push your local master branch to the <NAME> master branch.