3

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?

Donato Szilagyi
  • 4,279
  • 4
  • 36
  • 53
dopatraman
  • 13,416
  • 29
  • 90
  • 154

1 Answers1

8

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:

  1. Make changes in your working directory. This is most often writing some code.
  2. Build a commit by staging changes. This is done using git add.
  3. "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.

  1. Check what remote repositories are known by your local repository: git remote -v.
  2. If the GitHub repository is not shown, you'll need to add it: git remote add <NAME> <URL>.
  3. 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.
Community
  • 1
  • 1
simont
  • 68,704
  • 18
  • 117
  • 136