How do I backup my project with git? - javascript

I want to backup my project, so I have tried initializing a rep with
git init
and then commit all files with
git add .
git commit -am "first commit"
and now I want to push it to a repository (which is not only locally stored).
I know I have to do something like
git push origin master
I know that master is the name of my branch, but what is origin?
Where are the files stored? Do I have to create a repository on GitHub, so the files can be stored on GitHub's servers or are there some Git servers which can store my files for free (I assume not :D)?
So do I have to first create the repository on GitHub and then connect my local project with the GitHub repository with
git remote <url_to_GitHub_rep>

Create a repository in github and copy the git url(Something Like https://github.com/username/gitname.git ).
Then
git init
git add .
git commit -m "First commit"
git remote add origin https://github.com/username/gitname.git
git remote -v
git push origin master
Then You Will Be Asked Your Github Username & Password.
Now Enter Github Username and Password.
The Files Will Uploaded to your repository.
Thank You.

First of all you need to be have an account.

The most popular way to back up projects with git is using remote git repo.
For the remote git repo, it can be setup on your own server, or it can be hosted on github, bitbucket etc.
The remote repo is the place where you really version control or backup your project. And the local git repo works as working copy for remote repo. You can connect remote repo with local repo with the situations:
Already has local repo (the situation as you have):
git add .
git commit
git remote add origin <remote repo URL>
git push -u origin master
Note:
origin is the default name for the remote repo (similar as master is default branch name), of cause you can use other names to replace origin.
-u (--set-upstream) option is set the tracking relationship between local master branch and remote master branch. You can find your local master is behind or ahead of remote master branch by git status.
Not has local repo:
git clone <remote repo URL>
cd <repo name>
git add .
git commit
git push origin master
Note: when you clone a remote repo locally, git will set the remote name as origin by default.

Related

How to Update Deployed React App on GitHub Pages

recently I have deployed my first React App on GitHub Pages
https://karan-dhingra.github.io/lct/
Now I updated react app and my changes are not reflected on GitHub Pages. But everything was working well on Localhost. So, please guide me on how can I update my deployed React App on GitHub Pages.
Just we need to run 3-4 commands
git init
git remote ****************.git [ Here we will add our repository link ending with.git you will found it in the code option in your repo.
npm run deploy [Make sure you have installed gh pages first]
git add .
git commit -m "Here you write message while committing, you can write anything here"
git push origin master
So, with using these commands everything will work well.
Make sure you save the code in the IDE. after saving check with "git status" command and commit & push to git repo and the changes will be reflected
In my case, the lines below have helped. My app is deployed via gh-pages:
git add .
git commit -m '...'
npm run deploy

How to merge git files in one directory and add the files to the staging area

How to initialize a git repository on a directory that contains a subdirectory that has git already initialized?
I am working on a MERN application and I have created a root folder "chatapp".
Inside the root directory, there are two sub-directories:
client
server
I am using React for the frontend and react comes with git already initialized.
I want to initialize git inside my root directory which contains the client subdirectory with git already initialized.
And when I run git init, it initialized well but when I run git add to stage the files for commit, it brings an error: screenshot of my code editor
I need to add both the client and server files to my git repository.
Do I need to first initialize git in the server file separately then merge or how do I add both files to the staging area?
How can I add do this without seeing the error to avoid conflicts in the repository?
Thank you,
You need to use Git Submodules and add the repo separately.
For example: git submodule add https://<GIT_HOST>/server.git server and git submodule add https://<GIT_HOST>/client.git client
Or, you could just not have those be Git repos.

How to update heroku app (Node js) from github repo?

I have tried the same as React deploy precess.
git status
git remote add origin <repo link>
git commit -m "node js"
git add .
But it does not work.
can you know me how to update the node js app in Github that I have been uploaded to the Heroku server.
In your app deployment settings, add a repository to link your app with it :
After that you can enable the automatic deploy on a specific branch and each push or deploy manually a branch.

Github Pages Error Message

I have some questions about gh-pages. I have a githab repository and project
Page as githubpages. In the project directory that I use the
Github repository created has git push, git pull, git build and
git deploy without problems. The site can be found at http://ux.example.com
call. Unfortunately, it is not possible to make the page using https://ux.example.com
call. In the settings, it is explicitly pointed out,
That it is not possible to call custom subdomains with https.
I have on another computer the repository via git clone
downloaded. Git pull, git push, git build works perfectly.
I suspect that the cause is the subdomain. How do I solve the problem?
With git deploy I get the following error message:
yarn run deploy
yarn run v0.27.5
$ gh-pages -d styleguide
fatal: attempt to fetch/clone from a shallow repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Git push -u origin master

I've trying to push my files into git, but it doesn't work.
This is what I've done before.
git init
git add .
git commit -m "Start"
git remote add origin git#github.com:user/repo.git
The first git push -u origin master works.
After changing some files and trying to git push -u origin master again
it doesn't work.
To git#github.com:denis89/gaw8d3.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git#github.com:denis89/gaw8d3.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.
Also git pull doesn't work, because of unmerged files.
Any ideas?
You will not be able to push because your head is behind the remote thus the non-fast-forward message. You must perform a git pull before you can push. A git pull actually performs a git fetch and then a git merge.
You say git pull does not work because of un-merged files. This is most likely caused by one of two things:
conflicts.
If you have conflicts you need to resolve them and then commit locally to merge.
you have uncommitted files that are conflicting with files you are attempting to pull.
In the second case you can't pull because the remote has a more up to date version of a file you have made changes to but have not committed your version and so git cannot even attempt to merge the versions.
You will have commit your version of this file and then try to merge again. If you don't want to commit those files you must stash them before you can pull.
In both cases a simple git status command will show you committed files uncommitted files and conflicts.

Categories

Resources