Reputation: 928
I'm on Mac OS. I open up terminal, go to folder ~/../../Search_Engine
which contains a bunch of Java files already pushed to my GitHub, as well as folders of prior versions of the project (in folders like Project 1
, Project 2
, etc.) So I'll run you through what I'm doing exactly and where my problem arises.
Again, I cd
to ~/../../Search_Engine
, which I already used git init
on. I try this:
nathan-fuller-mbp:Search_Engine nathanfuller$ git add Project\ 2
nathan-fuller-mbp:Search_Engine nathanfuller$ git commit -m 'project 2 commit'
and then this mess happens...
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# AssignmentsInterface.java
# CommandInterface.java
# DatabaseInterface.java
# DocumentInterface.java
# ExpressionTreeInterface.java
# HistoryInterface.java
# InvertedFileInterface.java
# InvertedListInterface.java
# MapInterface.java
# NextCommandInterface.java
# Project 3/
# Project 4/
# Project 5/
# Project 6/
# ResultListInterface.java
# TestHarness.java
# WordListInterface.java
nothing added to commit but untracked files present (use "git add" to track)
nathan-fuller-mbp:Search_Engine nathanfuller$
So this is my first problem. Can anyone explain to me what is happening when this happens and why it happened in the first place?
Continuing on... I try to push (I probably shouldn't because we already hit our problem, but I'll just show what happens anyway):
nathan-fuller-mbp:Search_Engine nathanfuller$ git push origin master
To https://github.com/NateFuller/Search-Engine.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/NateFuller/Search-Engine.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.
nathan-fuller-mbp:Search_Engine nathanfuller$
Any suggestions? Please let me know if you'd like me to post more details.
Upvotes: 0
Views: 981
Reputation: 568
So you navigated to a directory where you already had initialized a git repository (git init). You successfully added the directory "Project 2" to the head of your git client (git add Project\ 2). Then you proceed to commit your current head (with only Project 2 in it) to your repository.
After a successful commit Git usually gives feedback about all the untracked files in your current directory. And as you can see Project 2 is no longer present. Use the command git log to see all the commits you have done, in your project.
Judging by the terminal feedback, you didn't add all of your project files after initializing your git repo. git init always initializes an empty repository. You can add your project files, if they're all in one directory, using git add . (don't forget the dot).
Before continuing on with your second problem. It's good to be aware that you can only push to a remote repository that has the same history as your local repository. If your project is already on github, I'd use git clone (use your favourite search engine) to make sure you first have a git repository with the same history. If you prefer to continue working from your local repo, I'd reinitialize your Github repo and then push your local repo to it, because an empty repository is the only one where previous history doesn't have to match in order to push to it.
Upvotes: 3
Reputation: 169
It seems like you aren't actually adding the files with you git add
command.
I would check the status with
git status
To add the entire Project a short cut is
git add -A
Upvotes: -1