How to do the "Save your Code Revisions Forever with Git"?

How to do the "Save your Code Revisions Forever with Git"?
0

#1

Hello!

How to do the “Save your Code Revisions Forever with Git” challenge?

Now i am studying git.


#2

There’s a desktop app for Git-it, if you have trouble completing it on cloud9. Otherwise, just follow the directions in the lesson.

  • Create an account on Cloud9

  • create a workspace

  • install git-it by the command: npm install -g git-it in the console

  • follow exercises, the actual instructions are at jlord.github.io/git-it

  • if you installed it correctly, you’ll see cmd menu like below:

    GIT + GITHUB : VERSION CONTROL + SOCIAL CODING

    » GET GIT [COMPLETED]
    » REPOSITORY [COMPLETED]
    » COMMIT TO IT [COMPLETED]
    » GITHUBBIN [COMPLETED]
    » REMOTE CONTROL [COMPLETED]
    » FORKS AND CLONES [COMPLETED]
    » BRANCHES AREN’T JUST FOR BIRDS
    » IT’S A SMALL WORLD
    » PULL, NEVER OUT OF DATE
    » REQUESTING YOU PULL, PLEASE
    » MERGE TADA!

    HELP
    EXIT

I was having trouble with it on Cloud9, so I downloaded the git-it desktop app(found it on google).


#3

Thank you, you helped me!


#4

You’re welcome, glad I could help.


#5

hi @rmonastra,

I have just followed the instruction on https://github.com/jlord/git-it-electron and installed Mac version of the GitHub Desktop (v 4.3.2) which I downloaded from (https://github.com/jlord/git-it-electron/releases).

After opening GitHub app, I see first step : Install Git (why ?? I thought Git is included in GitHub) and also “Mac: open GitHub Desktop and from Preferences, select the command tools install. Use the terminal app as your terminal”.

Wait … but there is no Preferences anywhere on the GitHub app ?? Am I missing something ?

Next, I start a terminal session on my Mac and type in : git --version . I get a prompt to install xcode, which I read from the original guide (https://github.com/jlord/git-it/blob/master/original-readme.md) can be ignored. Not installing xcode =>neither git --verson nor git command works on my Mac terminal session.

What am I missing or doing wrong ? Please help.

Thanks


#6

@atan4583,

My experiences with Macs are limited. Even in Windows, Git commands give me trouble unless I use the Git shell included with the Github app. I’ve followed numerous different instructions for setting up Git on my Windows machine. Preferences are the options in the settings.


#7

For when yer done with that challenge and realize you might need to continue learning you some git…

In one of @P1xt 's guides (that are now depricated and linked on GitHub) (whhhhhaaaaaa? theres a hub? full of git?)

the FAQ, right at the top, has a whole bunch of git exercises and resources.

Use them all. It’s taken me three or more passes through various resources to sort of get git. get git? I highly recommend it.

It’s worth the extra time as you continue to code…

Also this series. Watch it if you get a chance. GitHub for Noobs
Learn about that Hub fuullll of git


#8

Thanks ! Shortly after posting my question, I resolved the impasse myself (after mucking around with it for a bit) and was able to finish the challenge on C9.


#9

Yup, just completing the challenge alone is not sufficient to master the subject, I need to find more learning resources to supplement what I learned. For example, I don’t know how to resolve the following error -

I set up a local repo on my Mac and tried to repeat the challenge after completed it successfully on C9. I named this repo “hello-world”, created a file named readme.txt in it and associated it to the remote (origin) on GitHub. So the Mac setup is identical to that on C9, the only difference is the file contents, with the C9 file contains “xxxx” and the Mac file “yyyy”. I was able to commit the Mac readme.txt file with no error, but wasn’t able to run ‘git push origin master’. This is the error I got -

To https://github.com/atan4583/hello-world.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/atan4583/hello-world.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

I tried ‘git fetch’ then ‘git checkout readme.txt’, thinking to first get the C9 copy (contains “xxxx”) in origin to replace the Mac copy (contains “yyyy”), then edit it to “yyyy” before committing and pushing to origin. The checkout command didn’t appear to do anything. When I tried ‘git pull origin master’ on my Mac, I couldn’t get past the following error -

From https://github.com/atan4583/hello-world
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

How do I get past this error ?


#10

I strongly suggest you to set up a development environment on your mac by installing:

-Homebrew
-Xcode Command Line Tools. These include compilers that will allow you to build things from source.
-Git (and not the desktop version) with some base config

  • a text editor
  • a configured terminal

There’s this awesome git repo/guide that explain how to set up those thing in order:

Basically the first thing you need to install is homebrew (probably Xcode command line) and then proceed from there.

At the end you should have a decent dev environment to work with :slight_smile:
Hope it helps


How do I get past this error ?

Have you tried a simple
git pull
followed by a
git status
Hopefully you should see an already up to date


#11

Thanks and appreciate the tip @Marmiz , I shall try it out.

Regarding the error - I did try git pull, which gave me the following -

warning: no common commits
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 6 (delta 0), reused 6 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), done.
From https://github.com/atan4583/hello-world
 * [new branch]      master     -> origin/master
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> master

Tried the hints ('git pull “remote” “branch” ’ and ‘git branch --set-upstream …’) out too, none works and I got stuck. Whereas git status produced this :

On branch master
nothing to commit, working tree clean

In my prior (quite shallow) experience doing this on bitbuckit, ‘git pull’ and ‘git status’ would do the trick, if not, then ‘git fetch’ + ‘git checkout’ would fix it. I thought github and bitbuckit work pretty much the same, am I mistaken ?

Lastly, to install Git on my Mac, do I need to un-install the desktop version (this was the result of following the instruction for completing the challenge) and the xcode command line tool ? I have a text editor atom installed, what do you mean by a configured terminal - a Mac terminal session configured to work with git ?


#12

This lines let me believe that that you should specify which origin you want to pull from.
so you should git pull origin master.

But before that you can git remote show origin to see the URL origin is associated with.

Lastly, to install Git on my Mac, do I need to un-install the desktop version (this was the result of following the instruction for completing the challenge) and the xcode command line tool ?

Absolutely not.

what do you mean by a configured terminal

I have configured my terminal settings so that it will always show (with some color) the brach you’re working in.
You’re fine even without, but I find it useful to have it already displayed on my terminal as:

marmiz at MacBook-Pro in ~/dir/project on <branchname>


#13

hello @Marmiz, but I couldn’t get past this error with ‘git pull origin master’ in the first place -

From https://github.com/atan4583/hello-world
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

The output from ‘git remote show origin’ produced this -

* remote origin
  Fetch URL: https://github.com/atan4583/hello-world.git
  Push  URL: https://github.com/atan4583/hello-world.git
  HEAD branch: master
  Remote branch:
    master tracked
  Local ref configured for 'git push':
    master pushes to master (local out of date)

Is the last line local out of date the cause of the problem ?

I also just tried update readme.txt on Mac again, then ‘git add readme.txt -a’ to commit with no issue, but then ‘git push origin master’ gave this error

To https://github.com/atan4583/hello-world.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/atan4583/hello-world.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

Back to merry-go-around, sigh ! what else can I do (I feel like an idiot) ?

Mind sharing how you configured your terminal settings to show with color the branch you are working in ?
Thanks again


#14

There is a good explanation on this thread of SO:

Give it a read and see if it’s of any help in understanding what cased you this issue in the first place.
Then if you are sure about the file you’re trying to merge you can try:

git pull origin branchname --allow-unrelated-histories

Hope it helps.


My configuration is pretty similar to the one explained in the Github repo I’ve linked before.
(this is the .gitconfig file for reference), you can follow his steps and pretty much config it as he does :slight_smile:


#15

Thanks ! Read a few posts on stackoveflow, it seems different scenarios can lead to same errors I got, I am not sure which is causing which now. Tried --allow-unrelated-histories option, the whole mess got even worse.

I ran out of patience and deleted the whole hello-world folder from Mac, re-create a new hello-world folder then ‘git remote add origin https://github.com/atan4583/hello-world.git’, followed by ‘git pull origin master’. This basically got me the C9 version of readme.txt file to my Mac.

My observation is - If there are 2 different files of the same name from 2 repos of the same name to be added to the same remote origin, only one of them can be added. There is no way to merge the other remaining file to the remote origin.

Is this restriction by design or a bug of Git ?


#16

I prefer Ubuntu for use git/Github.

  1. Read: https://git-scm.com/book/en/v2

But, the basic about Git/Github is:

  1. Install Git in your PC/Mac
  2. Use the terminal for commands (i just used terminal)

The basic commands for write and enter in terminal (you need learn about this commands):

git init
git remote
git add
git commit
git status
git push
git clone


#17

And what did you use as terminal? I am having trouble too with this challenge.