Wednesday, October 10, 2018

GitHub - create a repository and push content

Step1: First, I logged in to github.com and created a repository on the site: javascript-fetch-calendar

Step 2: Change directory to the current project folder and run the following command:

$ git init
Initialized empty Git repository in /home/ubuntu/Documents/my-foundation-project/my-javascript-project-05-calendar/.git/
$

Step 3: Now check the status of the project using the command:
$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)

calendar-app.js
calendar-data.js
index.html
init.js
style.css

$

Step 4: Add the files in the directory to the staging:
$ git add .

Step 5: Let us now check the status again:
$ git status -s
A  calendar-app.js
A  calendar-data.js
A  index.html
A  init.js
A  style.css
$


Step 6: Now, let us pull the existing stuff in the project to the current directory:

$ git pull origin master
warning: no common commits
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/sashank786monitrahealth/javascript-fetch-calendar
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
fatal: refusing to merge unrelated histories
$

Step 7: After this, when I tried to push

$ git push origin master
Username for 'https://github.com': sashank786monitrahealth
Password for 'https://sashank786monitrahealth@github.com': 
To https://github.com/sashank786monitrahealth/javascript-fetch-calendar.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/sashank786monitrahealth/javascript-fetch-calendar.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.
$

To solve this problem. I searched on google to find the following two stackoverflow URLs:

The solution was to use the -f switch to push the content:

$ git push -f origin master
Username for 'https://github.com': sashank786monitrahealth
Password for 'https://sashank786monitrahealth@github.com': 
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 2.24 KiB | 2.24 MiB/s, done.
Total 7 (delta 0), reused 0 (delta 0)
To https://github.com/sashank786monitrahealth/javascript-fetch-calendar.git
 + 476b3b8...fe8bcfb master -> master (forced update)


On checking the repository on github.com - I found the content inside the repository.

No comments:

Post a Comment