New to Git Hub I have code on my local system and I want to get the latest code there committed by other team member how I could do that - github

I need a command to update the latest code from the Master repository. Like SVN, we do an update and it will give you latest code.
I am trying to use
sudo git pull origin master
but it says already up to date. I have tried to do
git reset --hard HEAD
sudo git pull origin master
as well but it is also not working.

Try to check if you are on the right branch (master):
git branch
It should look like this:
* master
If it isn't, type:
git checkout master

Related

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

Eclipse Git (EGit) - How to revert local master back to remote master after a foul merge & commit with a local branch

I have the following setup:
Remote origin/master (default branch)
Locally, I got the master and created another branch - NewBranch.
Someone in my team updated master on the remote. I was able to pull in all the changes that they made.
However, while merging I had conflicts. Unintentionally, instead of updating NewBranch with the conflicted result, I have updated the local master with NewBranch (because master was the one that was currently checked out-or "active" in Eclipse). Furthermore I committed this change (locally) to my local master branch...
I was able to switch to NewBranch and merge it with all the latest changes (so my Newbranch is perfectly the way I want it).
Now, I'd like the master to point to the same version as remote master does.
So that in the future I have a clean merge between my NewBranch and the Master
I've tried to "Reset" the master, but after performing a hard reset, the Hash Ids b/w the local master and remote master still do not match.
I also have References in my git eclipse and the reference of FETCH_HEAD is the one I'd like my master to revert to.
How can I do this using git in Eclipse?
Thanks in advance
I am guessing you are asking these 2 questions?
Now, I'd like the master to point to the same version as remote master
does
If I'm right follow this, if you master should point to remote master
git pull origin master
If your NewBranch should point to remote master
git pull origin NewBranch
I also have References in my git eclipse and the reference of
FETCH_HEAD is the one I'd like my master to revert to.
Please right-click on project in your eclipse--->go to team----> check the git options
These commands will help you to revert to a specific commit
git checkout master
git reset --hard e3f1e37
git push --force origin master
# Then to prove it (it won't print any diff)
git diff master..origin/master
Alternative
Sometimes you may want to undo a whole commit with all changes. Instead of going through all the changes manually, you can simply tell git to revert a commit, which does not even have to be the last one. Reverting a commit means to create a new commit that undoes all changes that were made in the bad commit. Just like above, the bad commit remains there, but it no longer affects the the current master and any future commits on top of it.
git revert ~specificCommit
But remember this after git revert, if you want to go back, you need to read this Git revert be careful
before you do it.
git revert 45ae34 e34526a #created two revert commits
git revert HEAD~2..HEAD #by taking ranges, it will revert last 2 commits
git revert -m 1 <merge_commit_sha> #this basically reverts a merge commit
# To get just one, you could use `rebase -i` to squash them afterwards
# Or, you could do it manually (be sure to do this at top level of the repo)
# get your index and work tree into the desired state, without changing HEAD:
git checkout 34e2w34 .
git commit #commit here
Docs:
git docs: undo merges

Adding to Github from Visual Studio 2013 not working as documented

This is the online reference I am using. However when I enter the remote repository and hit publish I get an error
You cannot publish local branch master to the remote repository origin
because a branch with the same name already exists there. You might
want to rename your local branch and try again.
I dont want to rename anything as yet. I want the first version of the code to go into the master branch and at the same time create an upstream tracking branch locally.
Then I tried using the command line only. After creating a fresh repository, I ran the following commands
$ cd (project-directory)
$ git init
$ (add some files)
$ git add .
$ git commit -m 'Initial commit'
$ git remote add origin <url>
$ git push --force
This worked but now I have all my obj,bin,packages directories along with it. I don't want all those directories to go. Editing the git ignore did not help either. What I am doing wrong? Its taken more twice the amount of time to get the code into the repository than it has taken to write the code!
I only want my sources in the repository and have a tracking local branch to begin with.

Messed up my master branch on Github

While contributing to a github project that I had folked. I committed my changes to the master branch of my repo. By mistake I did a pull from the Project's repo. Now while I do a PR from my repo, it includes those changes too. I dont want that to happen, can anyone help?
Just reset your local master and push it back.
$ git checkout master
$ git reset <last_good_commit>
$ git push

Editing commits in github

Using Git Bash, I just edited some commits.
In the shell it says: Successfully rebased and updated refs/heads/master
I don't see the changes in my github profile.
Do I still need to git push origin master?
I've tried this and it rejects it.
What do I need to do to finish this process?
You need to git push -f origin master