GIT confusion with restKit - ios

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

Related

How do I pull your last commit from GitHub to C9?

So, I kind of messed up and went and deleted all my files on C9. I haven't saved anything yet, so I'd like to pull my last commit into my C9. I read somethings that said I should download the zip file of the commit, but I don't really know what to do with that. If anyone could help me I would really appreciate it!
If you guys need any more info, I want to pull from my last commit because I deleted all my branches except my master branch and all the hidden files that I might need later. I couldn't really find anything about pulling into C9 from Github so I thought this would be a good question to ask you guys.
you can delete all the files that you do not need then run the following
cd ~/workspace # make sure you are in the right folder
git init . # create new git repo instead of the one you've deleted
# now add your github repository as origin
git remote add origin git#github.com:jinntakk/upskill_saas_tutorial.git -f
git remote set-head origin -a
git fetch # fetch your commits from github
git reset origin/HEAD --hard # reset working tree to the remote

Git pull request - how to pull and update Sublime

I've made a stupid error which has messed up my database on a Rails App I'm working on. Luckily I'm on a branch and haven't committed any changes so the version on Git is in working order.
How do I now pull through the Git version and update to Sublime so I can carry on working as if nothing happened?
I've just done git pull origin master but it says up to date so I've obviously done something wrong.
I'm not keen on a db:drop so I'd rather do it this way if possible.
You can't pull again, because you already pulled every commit from your remote.
Add changes, stash them, remove the stash:
git add --all && git stash && git stash drop
This will remove every uncommited change and bring you back to the latest commit on the current branch.
git checkout 01h5y77d (find this in git, a version of the app which works)
This would print "HEAD is now at 01h5y77d..."
You don't have to commit because you did not commit the mistakes yet :)

problems with pulling or pushing the code

My question is very basic but still it is unclear for me. I am working on a rails project with multiple developers. All of them can pull or push the project. So let me explain my scenario. If I am making changes in my code for the first time and the other developers are also making changes, when I try to push the project I am able to do so. But the other developer face problem in pulling the project. After that If they are able to make changes and pull the project then I am unable to push the project or pull the project. This is how we push the project first:
git add .
git commit .
git pull origin master
but the error comes warning: Cannot merge binary files or I get the error git pull fails with “Untracked working tree file 'blah' would be overwritten by merge
The problem is coming because you and your friend doing changes on the same line of the file and git is unable to decide which one to take. So in this case its better to go for stash first to save your code.
The code will be:-
git stash :- To save your code
git pull :- To pull the code from git
git stash apply :- To merge your changes with the pulled files, if any merging error is coming then it will hit an error saying merge-conflict,you have to resolve that manually.
git add :- To add the files
git commit -m "Commit message" :- To commit it
git push :- To push to the repo.
I think this will solve your problem
git checkout accepts --ours or --theirs options for cases like this. So if you have a merge conflict, and you know you just want the file from the branch you are merging in, you can do:
$ git checkout --theirs -- path/to/conflicted-file.txt
to use that version of the file. Likewise, if you know you want your version (not the one being merged in) you can use
$ git checkout --ours -- path/to/conflicted-file.txt
ref:Resolving a Git conflict with binary files
In your case the file is 'blah' in the working directory of remote location. so u can keep one of them.

Can't push changes to GitHub

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.

Setting up Github on a new computer

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)

Resources