Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Development Tools

troy beckett
troy beckett
12,035 Points

pushing and pulling with git??

I'm currently trying to learn git and finding it a bit difficult. I went onto github and created a repo. I used my computer to create some work to push to my github repo. I found the commands and thought it would work easy.

However when I made the repo on github I also put a readme.txt with it. So when I try to push to the remote repo, git won't do it because it doesn't have that readme.txt on my local computer.

The hint it gives is 'maybe pull first'. How do I solve this problem. I know I could obviously make a new repo with no readme.txt but I'm interested in possibly figuring this out. As I think it will help me learn quicker.

2 Answers

Hi Troy,

You'll need to 'pull' the readme file from the remote git repo so that it is available locally. I don't think you can commit a local repo (on the same branch) that is behind the remote one. So, get them aligned first, then you should be good to go.

What IDE are you using for this? What commands are you using on your machine that git is not liking?

Also, have a look at this post from yesterday that might give you some ideas.

Steve.

troy beckett
troy beckett
12,035 Points

Hi thanks steve,

I understand exactly what my problem is and why. But I'm struggling to resolve it.

Just to go over it once more my problem is this:

I can't push because the tip of local branch is behind the remote branch. Because the remote has a readme.txt that the local branch doesn't. Which I think confuses git. So now I guess the answer is to pull the readme.txt into my local branch. However I can't work out the commands for this.

I just typed 'git pull' literally on it's own but it didn't work it gave me the hint:

git pull <remote> <branch>

But this confuses me. I understand the problem just don't know what to write. I'm reading round currently trying to work it out. I'm using git bash by the way on windows

Would git clone http://github.com/user/repo.git help? That creates a new project, though - you've set up a project at both ends, modified one and want to sync them together.

Maybe try a git pull origin master?

Google gave me this which looks good ... combining git fetch and git merge sounds like what you want to do. That's, effectiely, what git pull does; you just need to stipulate where to pull it from and to - that's the origin masterbit.

troy beckett
troy beckett
12,035 Points

thanks for your help.

"git pull origin master " worked for me. Is they any chance you could possibly explain that command in english to me. Also what have I done here, is this what they call merging branches?

For anyone else that gets into a similar situation when you type "git pull origin master" you get a screen where it wants you to add another commit message. The screen at first feels as if it's looked but it's git taking you to an editor called vim which doesn't work the same as usual git. So look out for that. The commands aren't hard just confusing.

Steve thanks for your help again.

Glad to help.

This isn't quite the same as merging two branches; no, but you are using branches (the main trunk, really). Read my answer in this post (same as the above one) for some ideas on how branches work. They're pretty straightforward.

What you've done here is as follows. The remote main branch is called master. Your local main branch is called origin. So, git pull origin master pulls the changes of master and sticks them in origin. When you push up to the repo, you'll use (initially) a git push origin master; same principle.

Steve.