I am an almost perfect beginner at Github so please humor me with this elementary question.
I have a laptop PC that I've been using to interact with a repo on Github. I just bought a Mac and I would like to do my programming on both machines.
I have installed Git on the new machine and I have set up my username, e-mail, and Github token on the Terminal.
What are the basic commands I need to do this:
Download the repo from Github the first time? I've created a new folder on my Mac but going there and typing git pull git#github.com/sscirrus/repo.git produces fatal: not a repository (or any of the parent directories): .git.
Upload those changes again such that the main repo is updating cleanly with each new push. I assume that once I have the code in my new folder, it would be a matter of git add . and git push with password entry?
I am reading through tutorials on Git but just want to make sure I'm doing something sensible for my situation before my newbieness screws up a lot of prior work. Thank you!
Go through this book, http://progit.org/book/ and http://gitcasts.com/ for video tutorial.
And I recommend you follow these steps
Clone the repository (git clone repoAddress)
create a new branch (git branch branchName)
checkout that branch (git checkout branchName)
make changes and commit in that branch (git add files)
checkout master (git checkout master)
perform a pull (it updates the local repository with the remote one) git pull
If there is change, checkout the branch and rebase it with local master
If there is conflict resolve it and add that file and make a commit again
checkout master again and merge the branch (git merge branch)
push the commits to the remote repository.(git push)
If you want a GUI tool, then there is GitX which is made for Mac OS X. http://gitx.frim.nl/
Download the git repo for first time - do a clone of the repo first. this will bring your code from github to your machine for the first time.
git clone your_git_repo_url
from second time, you can
git pull your_git_repo_url
Upload the changes after commits
git push your_git_repo_url
Please read scott chacons git books. these will get you the basics of git. and learning this will help in the long run.
You need to use git clone, not git pull.
You'll want to git commit after add and before push. add just adds something to the index (Worst name ever. The "index" is essentially a pending commit.) and commit actually commits it to your repository. push then pushes committed stuff from your local repository to a remote repository.
Whilst there's a lot to be said for using git from the command line (to help understanding) you might like to try the github clients (for mac & windows - download them from the github homepage - at the bottom in the section marked 'clients') which I'm guessing might not have been available when you posted your question.
The Windows one lets you specify a default storage directory (where it clones the repos into) - the Mac one prompts you with each clone as to where you want to stick it.
Both very easy to use to do what you want (clone, pull, push etc and also good for seeing what branches you have and changing between them)
Related
So i am learning to ever so slowly use git to get me the latest update of RestKit as the old version has retain cycles...fair enough HOWEVER, when i pull using the gitHub Client it does not give me the AFNetworking files, which i was then told use the command
git submodule update --init --recursive
which i do, problem is that i noticed that after running that i run
git submodule status
It has taken me off the master branch and put the HEAD back in thus reverting me to old stuff. and hence back to leaks and stuff.
So i thought maybe i could install using cocoapods or perhaps put a submodule within the restkit submodule for AFNetworking...all did not seem to work and now i have followed this guide How do I remove a submodule? up until the last step as i dont know what committing will do? i hope it does not commit the fact that i deleted everything onto the restkit site? i am so confused, initially all i wanted to do was switch the current branch submodule i have to the master.
Assistance would be much appreciated.
EDIT:
Okay as to answer what Commit does, commit only affects your copy of the repository and will in no way affect the remote "main" repository everyone else gets their code from, so in essence i was able to commit it, then run a brand new submodule from the branch i wanted, But the question still remains Is there a way to switch the branch you pull your data from when using the update with --recursive?
Simply go in th e RestKit directory and type:
git pull origin master
(if you use the master branch of course)
Also, if you need to update all your submodules, just go to the root of your project, and type:
git submodule foreach git pull
git submodule update is confusing, here what it really does:
When you invoke git submodule update it looks in the parent repository for a SHA for each submodule, goes into those submodules, and checks out the corresponding SHAs.
As would be the case if you checked out a SHA in a regular repository, this puts the submodule into a detached HEAD state.
EDIT
To switch branch of a submodule simply, let say 'development', simply do in the submodule git checkout development and then you should be able to do git pull origin development
I can't seem to figure out how to commit my files to GitHub.
I am using RubyMine 4.5 on the MAC
I have git set up locally
I have a private account on GitHub
From the RubyMine Preferences, I have my GitHub credentials properly set up (and acknowledged as such by RubyMine), but it did not give me an option to select a repository on GitHub.
How do I commit file to the GitHub repository? There are too many CVS and Git menu items in RubyMine.
PS: I've read the online help sections (the only thing available to me), and I followed the instructions in the GitHub integration, but the directory I'm trying to commit is failing to push to GitHub, with RubyMine telling me that there was nothing to commit. This is the first time I use RubyMine for GitHub. Nothing about this on StackOverflow.
Okay, I think I've recreated your situation locally and it appears that RubyMine has terrible support for managing remotes. If you create a Git repository locally, then (separately) create a repository on GitHub, there's no obvious way to marry the two from within RubyMine.
Basically, you need to set up GitHub as a remote for your local repository from the shell, and once that's done then RubyMine will be able to push as normal.
Please note that the below instructions assume you want to overwrite your GitHub repository with the full history from your local repository -- If your GitHub repository has data that you do not want to lose, do not execute these commands! See Below.
Open up Terminal:
cd /path/to/my/project/root
git remote add origin https://github.com/yourusername/yourrepo.git
git push -u origin +master
Now, RubyMine should be able to push to your GitHub repository via VCS > Git > Push
If your GitHub repository has already been committed to and you don't want to lose those changes, you'll need to either create a new GitHub repo or clone your GitHub repo into another folder and merge your local repository into the clone.
This can be avoided entirely if you're trying to push your existing local repository to a new GitHub repo: Simply use the VCS > Import into Version Control > Share project on GitHub option and use the dialog to create a new GitHub repository.
Update: I couldn't get either of the first two solutions provided to work, so I'm providing more detail and setting a bounty.
I have previously forked a github project called Enki (a Rails blogging platform) and then customized it and deployed it on Heroku.
Now I want to start a new Enki blog. I can't fork Enki again, because it's already forked and customized for the first blog. I now cloned it from the author's page, and wanted to add a new repository on my github page so that I could deploy it to Heroku. Here's step by step instructions that I followed
git clone https://github.com/xaviershay/enki.git valentines
cd valentines
git checkout -b myvalentines
bundle install
cp config/database.example.yml config/database.yml
git init
Message
Reinitialized existing Git repository in /Users/mm/Sites/valentines/.git/
1) Why the existing repository? Did I do something wrong? So it's going into the same repository (as the original fork?) even though I've named it something else?
Made code changes then did
git add .
git commit -m "made code changes"
2 files changed, 193 insertions(+), 157 deletions(-)
rewrite Gemfile.lock (70%)
2) Does the fact that it's writing Gemfile.lock mean that it's not changing the branch but rather the master?
Next I created a repository on GitHub
git remote add valentines git#github.com:Username/Valentines.git
git push valentines master
As you can see I, following Ksol's suggestion, used a different word than origin but it didn't work 3) Problem - the GitHub repository 'Valentines' did not show the code changes that I made, but was rather the original gem
Just use another name for your remote than origin?
Adding to #Katen's answer:
You can also use branches for this. For example, your forked repo could contain these branches:
master (pristine code from the author's repo. You may periodically update this)
blog1 (your first blog)
blog2 (your second blog)
This way, to begin working on new installation and customization of this blog engine, just run these commands.
// assuming that you completed and committed your work on a current branch
git checkout master // switch to original code
git checkout -b blog3 // "fork" it to a new branch and switch to that branch
1) git clone will point to the original repository, regardless of the local directory you place it into to. You created a new branch w/ git checkout -b, but it's not a new git repo
2) This looks normal, rewrite is just telling you that you made a lot of changes to that file.
3) I believe this is because you didn't push the new branch to your github page
git push valentines myvalentines
you can also update your .git/config file so origin is your new location. Similarly, there's no reason your master branch need be a copy of the enki master branch, but you should keep a reference to it so you can pull future updates.
I had been using a Subversion for my source control, combined with git ONLY to deploy (push) to heroku. My pattern was: Update local working copy from latest master at remote subversion repository. Then do git commit and git push heroku (Git was set to ignore .svn stuff). This working copy I only used to push to heroku, I had another subversion folder for doing live development, and committing to the remote subversion repository for tracking.
I have now switched to git fully. I did a complete import from subversion into a new remote git repository. I've successfully been working on my local working copy of the git repo (origin), and pushing changes when it suits me (also collaborating with one other developer, but I basically run the operation).
MY Question:
I would now like to return to my OTHER git working copy that I had previously been using to push to heroku (that has .svn/ stuff in it as well). I'm thinking of just adding my new git repository as an [origin] entry in the .git/config.. pulling the latest changes from my new git remote, and pushing to heroku, but I'm wondering if it will freak out.
It will try and merge and get confused won't it? AND, even if the pull worked, will the heroku remote get confused about a push that originated from some new git repo?
I could clobber (delete) that working copy (used to push to heroku from subversion), and make a new clone of my new git repository, then add heroku to the .git/config. But I'm concerned pushing to heroku will still cause it to get confused, since I used to push from a different working copy.
Any advice would be great!
Thanks in advance!
If I understand you correctly, you want to switch back to the former SVN repository as your working copy, and you want to preserve the old SVN history?
There are a couple of options available.
Push the recent changes from the new Git repository to Heroku, then switch to the old repository and pull from Heroku. This will bring you old repository up to date.
Temporarily change the URL in the old repository's config file to point to the local path of the new repository. Pull the recent changes from there, and then revert back to the Heroku URL when done. This will also bring your old repository up to date.
The first option is the most expedient, and the second is the long way round. Either way, you will have the same net result of an up to date local repository containing all history. The surplus new repository can be disposed of in either case.
Edit:
To address your concerns about whether Heroku will care about the origin of the commit, in brief, no the repository on Heroku is another git repository that accepts commits from authenticated users.
As long as the credentials are correct, the originating repository does not matter. This is the beautiful thing about DVCS - there is not one controlling or corruptible repository - It is entirely possible for you to now clone from Heroku on another machine and continue work from there. As long as your credentials are the same, the history will show any and all commits you push, but does not care where from.
If your desire is to simply use a clean repository to work with, the new one will be the favorite. The old one can be deleted without ill effects.
To prove this - check the SHA-1 hashes for a commit in both new and old repositories, and you will see they are identical. The hash is unique for all commits, and can be used to check the code integrity at all times. There will never be more than one change for any given hash.
As a side note, the repository is portable in that it is entirely self contained, and can be moved around freely on your storage space, or even be used on external storage such as a USB thumb drive.
I am developing some school grading software and decided to use Github to host the project. After building some code on my Ubuntu box I pushed it to Github and then cloned it down to my MacBook Pro. After editing the code on the MBP I pushed it back to Github. The next morning I tried to update my repo on the Ubuntu box with a git pull and it gave me all kinds of trouble.
Whats the best way to work in this situation? I don't want to fork my own repo and I don't really want to send myself emails or pull requests. Why can't I just treat Github like a master and push/pull from it onto all of my personal repos on different computers?
I'll assume your problem was that the machine on which you first created the repo crapped out when you tried to issue the git pull command.
When you clone an existing git repository (like you did on your 2nd machine, the MacBook Pro), you're automatically set up to so your git pull commands will automatically merge the remote with your local changes.
However, when you initially create a repo and then share it on a remote repository, you have to issue a few commands to make things as automated as a on cloned repo.
# GitHub gives you that instruction, you've already done that
# git remote add origin git#github.com:user_name/repo_name.git
# GitHub doesn't specify the following instructions
git config branch.master.remote origin
git config branch.master.merge refs/heads/master
These last few instructions configure git so future git pull's from this repo will merge all remote changes automatically.
The following is a bit of shameless self-promotion. If you use Ruby, I have created a Ruby-based tool that lets you deal with all these kinds of things with git remote branches. The tool is called, unsurprisingly, git_remote_branch :-)
If you don't use Ruby, my tool is probably gonna be too much of a hassle to install. What you can do is look at an old post on my blog, where most of the stuff grb can do for you was explicitly shown. Whip out your git notes file :-)
You can also add multiple SSH public keys.