Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJonathan Grieve
Treehouse Moderator 91,253 PointsI'm still not using Git or GitHub.
As I've shared before on Treehouse, throughout the past couple of years I've come to learn more and more that as a designer or developer you really should be using GitHub as a place to store and collaborate on code, but I just can't get into the habit.
Because I've been working for so long without it. There's one thing in particular that puts me off. Pushing and pulling to projects. I still can't grasp this concept.
- You "pull" projects from GitHub, I think that's right, so you download them to your computer.
- You make changes to contribute to the project, log these changes using git "Commits"
- You then push the changes back to the project using Git.
But how does this work. How does doing this not break the project as a whole? For example how does the changes I make merge in with the existing code on a Git repository. Am I making sense?
I'm thinking you make a branch where your version of the code goes and the developers, if they like it, merge it in with their master branch in the existing project.
After so long, not using Git, how can I get into it after so long just diving in to my programs and text editors?
10 Answers
Sue Dough
35,800 PointsFirst off. I want to say its hard to imagine getting anywhere far in a software project without it. Your going to make breaking changes etc over time and these NEED TO BE DOCUMENTETED and git makes this super easy.
Second off. You sound over whelmed with Git which is understandable. The best way to learn is create some fake dummy project to test it out. Break stuff, screw up, end up on stack overflow, and you'll know Git well shortly. There is seriously like 5-8 commands you'll ever run as a Git beginner.
git pull - just downloads your code and pulls it into your workspace basically
git commit - This is just the message that your going to assign with the commit. Think of a commit as saving progress in a video game once you beat a level.
git push - pushes the code somewhere. This could be to github, gitlab, bit bucket, remote git server, or even to deploy your web application!
Do not worry about merge issues. Git is super smart and takes care of this. It can intelligently merge without issues and if it can't you'll get a "merge conflict". You will be asked to fix the conflict before being able to merge. This way nothing gets screwed up. It will basically ask you "Hey we see these 2 lines of conflicting code, which 1 do you want to keep?" . You then choose which one. Once its resolved then you can merge.
Try this:
Sign up to Github and create a test repository
git clone https://github.com/username/repo-name.git
cd repo-name
Then add a file
Then run
git status
This will show you current status of project and that theres a new file.
To add all the files you can run
git add -A
Now if you run this command again you'll see the file has been added
git status
Now you need to commit
git commit -m "my test commit"
Then you simply can
git push
which will push the new file up to GitHub.
If you want to create a new branch. Just clone master. And then run
git checkout -b myBranchName
This will create a separate branch. If your working with teams its important to do this. Those branches can then be merged into master. You can do it on the command line or use GitHub user interface to merge the branch.
I hope that helps. The best way to learn these things is to set your worries aside and break stuff.
Karolin Rafalski
11,368 PointsThat's one of the best features of git/github version control- you (and anyone else all at the same time (or not)) can break stuff as much as you want, delete everything, fork and clone again, make 100 branches and try all sorts of different things and only your working version that you want to merge will ever make it to the master branch. The goal is to learn and practice and become worry-free about your learning process when using git!
John Steer-Fowler
Courses Plus Student 11,734 PointsHi Jonathan,
You ask a good question, and then you answer your own question it seems :D
You have the right understanding of Git completely. Github is a hosting site for git projects.
I often use Git for my personal projects on my local machine, however, like you I have never got into using Github and collaborating on projects. I really should!
Let me know if you ever want to try something together. I am always looking for some fun :D
Edit: I will just add one thing. You make a 'pull request' and they will be able to see the changes you have made. They will either accept or decline this request. If they accept, just as you said, your additions merge into the master branch
I massively recommend reading this guide if you want to get into using Github.
Jonathan Grieve
Treehouse Moderator 91,253 PointsSo if you're accepting a pull request it sounds to me like you'd better know your code and your project inside out and the implications for your project of accepting.
That said, Git is a version control system, so any project owner would have a saved backup of the last good version of the project I suppose :)
One last thing, what is a git project as apposed to another project. Of is if simply a project of any kind served through Git :)
John Steer-Fowler
Courses Plus Student 11,734 PointsHi Jonathan,
I guess when they say a 'git project' they mean a repository, so yes.
Good luck
Jennifer Nordell
Treehouse TeacherI too have have been struggling with this concept. Back when I was studying (in the stone ages) and using ANSI C (oh the horrors!) GitHub wasn't a thing. Our version of sharing code and looking for bugs was this. We'd print out pages and pages of our code and then switch with each other. Our primary way of debugging was to each have one blue and one red pen. All open braces were circled in red and all closed braces were circled in blue. Then we'd count the total number of red marks and blue marks and hold our breaths that the numbers didn't match! If they matched, then it was a logic error :(
So, I in theory like the idea of sharing ideas and coding and teamwork and synergy. But the practical aspects of it has me a bit stumped. So last night, I paid for the minimum account on github so that I can practice pushing and pulling and branching in private. Just so I can have a clue as to what I'm doing. If either of you fellows want to try to collaborate on something just for giggles, let me know! I'm down.
Jonathan Grieve
Treehouse Moderator 91,253 PointsOut of interest, how has the paid account helped you? How much did this cost? Yes, I'll look at this on the Github website later but I thought I'd ask :)
Jennifer Nordell
Treehouse TeacherJonathan Grieve It hasn't yet, because I'm still intimidated by GitHub. Which is why I decided to pay the seven dollars so I could have a private repository where I can play around and mess up stuff absolutely as much as I want to (or more accurately, need to). :) Again, I just got it last night and have spent all day trying to wrap my head around Angular.js and avoiding github like the plague :)
Karolin Rafalski
11,368 PointsI was very intimidated and hated git at first too. The only way to fall in love with git is to keep using it. It's worth going through the struggle/confusion/frustration of the learning curve and truly, once you get it, it makes sense and becomes 'easy.'
Sue Dough
35,800 PointsI agree completely. This is most of programming in general. You can't be afraid to break sh*t. Thats how you learn.
Karolin Rafalski
11,368 PointsI use a mac, so I am not sure about your first question. On a mac, when I run into a similar problem, I have to press q to fast-scroll to the end. I don't know if it is the same in your shell.
For your second question, git clone needs a url. If you have set up your repo on github first, then on the github page where there are a bunch of buttons (branch: master, new pull request etc.) there is a url there and a copy button. That's the url you would want to use.
If you want to initialize a new git repository with the command line and link it/send it to your github repository, follow these instructions https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
You will be using git init, instead of git clone. Hope this helps!
Jonathan Grieve
Treehouse Moderator 91,253 PointsHmmm Using Q seems to have worked, for now. Thanks. One problem solved. :-)
Karolin Rafalski
11,368 PointsAlso, you can use
git log --oneline
to see a truncated version of your logs
also
git log --graph
to see the branches and the merges
and you can combine the two:
git log --oneline --graph
even more options: https://git-scm.com/docs/git-log
Karolin Rafalski
11,368 PointsWould anyone like to collaborate on github? I was thinking of creating a repository for a simple HTML/CSS site that would let people try to create the ugliest CSS. Kind of like;
But rather than creating something really pretty CSS, challenge yourself to make something really unattractive (but still valid, properly styled (following an official style guide), CSS).
Everyone would use the same html, but then would create a new page with a link to their version of the ugliest CSS.
Everyone could contribute to the README and include great instructions and helpful links (also a great way to practice Markdown!) and help improve the HTML to make it informative and build out different components.
Anyone up for this?
Jonathan Grieve
Treehouse Moderator 91,253 PointsWould we be using a public Repo? Would you have the patience for a complete newbie with a very slow brain? Would we all be able to chip in at any time?
This could be good practice so if all that is cool I'd like to join in :)
John Steer-Fowler
Courses Plus Student 11,734 PointsHi Karolin,
I am definitely up for collaborating on this. I am also a newbie to Github, but have used Git for private projects.
Great idea by the way. Treehouse should really look at doing something like this so people can learn to use Github properly
Keep up the good work :D
Jennifer Nordell
Treehouse TeacherKarolin Rafalski I'm up for this! :) I know I need to learn git, and have taken the classes here, but I haven't really gotten my hands dirty with it in any practical way. This might be amazing! :)
Karolin Rafalski
11,368 PointsWould we be using a public Repo?
Yes!
Would you have the patience for a complete newbie with a very slow brain?
Yes! I am quite the newbie too! This would be practice/education for me too!
Would we all be able to chip in at any time?
Absolutely! I may even set it up as an organization and top contributors could become organizers too! But I have to read up on the best way to set it up and see if this makes the most sense.
Also, if it goes super well, I'll consider hosting it on github pages.
I think it could be fun!
Karolin Rafalski
11,368 PointsOK, the bare bones is complete!
Please feel free to collaborate on more than just the CSS!
https://github.com/Krafalski/ugliestcss
Thanks and I look forward to collaborating with everyone!
John Steer-Fowler
Courses Plus Student 11,734 PointsAwesome, I will be collaborating on this as soon as I get a free minute :D
Thanks Karolin!
Jonathan Grieve
Treehouse Moderator 91,253 PointsApologies in advance if I break it lol
Jonathan Grieve
Treehouse Moderator 91,253 PointsJonathan Grieve
Treehouse Moderator 91,253 PointsThanks Sue,. Thanks for a great and encouraging post.
Let me pick your brains even further if I may. Each time you make a commit, it's added to git log, isn't it?
git log
Unless I'm mistaken, the kind of projects you're talking about have hundreds, if not thousands of commits.
In my ignorance, I can imagine logs growing so extensive, that the compiler, whichever you use, runs out of space and when you want to bring up the log, suddenly you can't find the log and therefore the version of your file that you want. Is this making sense?
If I wanted to find a version of the project that was very early on, almost start from scratch but I've already made hundreds of commits. How else do I keep track of those. Is it a case of keeping a written log of all the committ you think might be important? Am I barking up the wrong tree?
Cheer.s. :0)
Sue Dough
35,800 PointsSue Dough
35,800 PointsYes its added in the Git Log every commit.
git log
is a favorite command of mine.
I have plenty of Git Repos. Some of them are open source projects and some closed. No matter how tiny the project is I usually use Git. There is just a lot of benefits.
Your log file won't explode on you. That isn't a concern at all! A git log on 30,000 commits takes micro seconds.
There is a few ways to work with history. There is no need to write anything but commits and you may want to use tags. One good way is so start tagging your releases 1.0.0 and 1.1.0.
Also if you type
git log
you will see a commit ID. If you want to go back to that very point in history of the code simply just do this with the proper commit ID:
git checkout ced66ed4e7c2c18873a67eb73b9603dd2bff50fa
Another very helpful commands for understand history I like is:
git log --graph --full-history --all --pretty=format:"%h%x09%d%x20%s"
This will show you pretty colors, merges, and help you visualize it a lot better.
Jonathan Grieve
Treehouse Moderator 91,253 PointsJonathan Grieve
Treehouse Moderator 91,253 PointsOkay thanks :)
I'm looking forward to having another play with Git tomorrow and I'll let you know how it goes.
Sue Dough
35,800 PointsSue Dough
35,800 PointsLet me know how it goes. Ping back here if you need to. I am happy to help.
Jonathan Grieve
Treehouse Moderator 91,253 PointsJonathan Grieve
Treehouse Moderator 91,253 Points2 main questions so far.
I use Windows 7 and the Git Powershell. Once the git log gets too long, I have to cycle through it, bit by bit until I get to "END".
From that moment on, the command line glitches badly. and not even Ctrl C to get out of the log will stop this. I have close and open a new shell to get going again. Is there something I can do to fix?
Secondly the git clone command doesn't seem to be working. Any idea why this might be? :)
Jonathan Grieve
Treehouse Moderator 91,253 PointsJonathan Grieve
Treehouse Moderator 91,253 PointsOne last one for now
Any idea what this error message means. It looks like I followed the right process for getting my git project on the repository at Github.
I feel like I've learned some stuff but still need some work :p
Karolin Rafalski
11,368 PointsKarolin Rafalski
11,368 PointsI don't think that is an error. I think it is success?
try
git remote -v
it should give you two lines that look something like this:
if you see that then you are set to push and pull to/from your computer/github
Jonathan Grieve
Treehouse Moderator 91,253 PointsJonathan Grieve
Treehouse Moderator 91,253 PointsI do get those 2 things, but I need to use
git push origin master
To attempt to put them on github which is when I get the error. It seems to be some sort of missing file.
Edit.
Karolin Rafalski
11,368 PointsKarolin Rafalski
11,368 PointsThat is the way I use it. I think
git push
without any other parameters is being discouraged/depreciated.The two parameters are important:
origin
is the alias for the url (you can see this when you dogit remote -v
) , you can rename it to whatever you want, in the below example it is being changed from origin to destinationgit remote rename origin destination
https://help.github.com/articles/renaming-a-remote/
Then,
master
is the branch that you are pushing to: Oftentimes you do not want to push to master. Master should be the 100% functional/production version of your code. This is sort of seems superfluous/silly if you are the only one working on your branch and you are not used to git. But, there is a lot of value into not automatically pushing to master.For example, let's say you are working with a few people on a project. As different people work on different features and merge them, you probably want to first merge them to a dev branch to make sure that the new merged features work as expected before merging them into master.
So, instead, your collaborators would type
git push origin dev
to merge into the dev branch instead of master.Or you may want two people to work on a particular feature, then they would be pushing/pulling from their feature branch before going into master. So they may be typing
git pull origin aweseome-new-feature
to download the branch they are working on.Lastly, if you have multiple repositories (i.e. if you deploy to heroku, it will add a repository), you don't always want to push all your changes automatically to all your repositories and in that case you would use the command:
git push heroku master
Karolin Rafalski
11,368 PointsKarolin Rafalski
11,368 PointsI googled your error and found this: http://stackoverflow.com/questions/27087483/how-to-resolve-git-pull-fatal-unable-to-access-https-github-com-empty
I have a generated SSH key for github. The set up of my first SSH key was tricky/very hard for me and I had help from more experienced people to set it up the first time. However, I have had to set up other SSH keys since then and it is not really so bad, I just get overwhelmed and doubt myself too much sometimes.
I think as long as you know it's a bit of a pain ahead of time, you can anticipate that and walk through the process of setting up an SSH key and you'll be fine.
Keep going! You've almost got git down!
Jonathan Grieve
Treehouse Moderator 91,253 PointsJonathan Grieve
Treehouse Moderator 91,253 PointsYea I'm with you on the getting overwhelmed and doubting myself. But I'll keep trying. I'll start a fresh repo and keep going until I get to grips with it but I'm not getting anywhere with this SSH stuff right now and I'll try another day :)
There's a best answer waiting for somebody though cos I've been helped a fair bit in this thread :)
Sue Dough
35,800 PointsSue Dough
35,800 PointsHi Jonathan Grieve,
Your first question >>>>> I use Windows 7 and the Git Powershell. Once the git log gets too long, I have to cycle through it, bit by bit until I get to "END". From that moment on, the command line glitches badly. and not even Ctrl C to get out of the log will stop this. I have close and open a new shell to get going again. Is there something I can do to fix?
My thoughts: Slow may be the "windows" itself as I can view logs of over 50,000 commits no problem on a laptop. Control C works in most Unix programs to cancel. When it does not work, the alternative is almost always "q" for quit. Git log will quit with the q key. I do not use Windows so it may be different there. As far as scrolling through faster, you can press the space bar to move down a complete screen, and the w command to move up a full screen. You don't need to go through the whole thing to quit.
Your Second Question >>> Secondly the git clone command doesn't seem to be working. Any idea why this might be? :)
My thoughts: This would never work because you are trying to clone something that does not exists. The git clone is almost always a URL not a word. Here is an old photo I found on GitHub that shows you where to find the URL. https://help.github.com/assets/images/help/gist/gist_clone_btn.png . Here is an example on how to git clone just some random trending project right now I found:
git clone https://github.com/typicode/json-server.git
Also have you ever thought of switching to Linux? :)
Jonathan Grieve
Treehouse Moderator 91,253 PointsJonathan Grieve
Treehouse Moderator 91,253 PointsThe first one is sound, now. Using Q to get out of git log seems to work just fine with no glitching or messiness at all.
To be honest I'm just a Windows kind of guy. :) I think you can get emulators for Mac and Windows but I'm so used to developing on Windows I don't have much time for anything else. Too many bad experiences trying to switch between the platforms.