0

I am using git to share a project across several computers. On one machine, I create a new directory (with various files in it) within the project. I then pushed this to the repository with the following:

git add directoryname
git commit -m "Adding a new directory"

Judging by the list of files, it seemed to commit everything. However, if I then issue the command

git pull

on another machine, the new directory doesn't appear. I've tried various other options e.g. git fetch but each time it says the local repository is already up-to-date. How can I pull this new directory down from the repository?

218
  • 1,754
  • 7
  • 27
  • 38

3 Answers3

3

You need to push it from the computer where you commited

git push origin mybranch

You can add the -u flag if you want to track it, so the next time you use git push it will push automatically the branch there.

blue112
  • 52,634
  • 3
  • 45
  • 54
  • 1
    I suggest adding `-u` flag (`git push -u origin mybranch`), so that next time you can simply write `git push`. Also, if you don't know what branch is, just use `master` (`git push -u origin master`). – GingerPlusPlus Aug 01 '16 at 15:43
  • Judging by the length of time git push took, I think this was uploading the folder and data (some quite large files). I used `git push -u origin master` however git pull still doesn't bring this new directory into the local repository on my other machine. – 218 Aug 01 '16 at 17:35
  • [Update] I ran through the following sequence: `git commit -am "New changes" , git push origin master` followed by `git pull` on the other machine. The new directory, one of the subdirectories, and one of the files therein have now appeared on my other computer. I've no idea why git isn't transferring everything or why it chose certain files. – 218 Aug 01 '16 at 17:42
0

Where do you host your repositories? There are many different options for this. This example uses GitHub

First, you must register with GitHub

https://github.com/

After you've done it, make sure you remember your login details.

Create a repository by clicking

button

Give it a name

gelloworld

Do your work on the project

git add .
git commit -m "Behold my awesome feature"

Grab a link to your remote repository

repos

Set up your remote repository on your machine

git remote add project01 https://github.com/edoroskevic/helloworld.git

Note: project01 can be replaced with whatever you like. It's simply a name for your remote repository that will be stored on your local machine.

After it has been set-up you can finally push your work to remote repository

git push project01 master

Note: project01 is the name I have given to this test repository and master is the branch I will be pushing to my remote repository.

After executing the above command you will be asked to provide your login details to GitHub (username, password). Enter those and check out your pushed updates on GitHub.

You may get a nasty fatal error when pushing. Saying something like...

Can't merge unrelated histories...

In that case you can run your push with -f like so

git push -f origin master

Note: -f will force the push on top of your remote. You can also add links between local and remote branches but this post is getting a bit too long.

Next time you are on another machine, you can

git clone https://github.com/edoroskevic/helloworld.git

This will clone the remote repository and set up all the links between branches automatically. Next you just keep doing your usual stuff adding, committing and pushing

Hope its helpful :s

e.doroskevic
  • 2,129
  • 18
  • 25
-1

The sequence that eventually worked is as follows:

Host 1 (containing new directory, 'Dir_new', with various subdirectories and files)

git add directoryname
git commit -m "Adding a new directory"
git push origin master

Host 2

git fetch
git checkout HEAD
git pull

Note this only transfers subdirectories which contain files. Any empty subdirectories are ignored.

218
  • 1,754
  • 7
  • 27
  • 38