How can i upload a Spring Java project to GitHub so i can show my work? - spring

I've tried through various ways, directly uploading the files wont work. I've tried through bash and nothing.

Do you have git installed?
# Create a new repository on the command line
#Go to Project Directory on your Computer, Open git Bash here
# run the following 1 by 1
git init
git add .
git commit -m "Comment here"
git remote add origin https://github.com/YourRepoPrefixHere
git push -u origin master

If you have a git profile and a repository you can take these simple steps to get it online:
Open a terminal and go inside the folder of the project you want to push to your git repository
Check if you are on the right git branch: git checkout
git add .
git commit -m "your messagge to commit"
git push origin -u "yourbranchName
If you have never set up your origin branch, you should add it before using it:
git remote add origin "github link"
To see if everything went well you can do a simple: git status.
I hope it will be useful to you my friend!

Related

git push to create new GitHub repo not working

I am trying to create a script that prompts for a name to give to a new GitHub repo, and then create the GitHub repo by pushing to the remote URL which the new GitHub repo will have. When I use the script I get these errors:
remote: Repository not found. fatal: repository 'https://github.com/JT-style/great.git/' not found
read -p"Enter the name of remote repository: " name
mkdir ~/rep/$name
cd ~/rep/$name
echo "#$name" >> README.md
git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/JT-style/$name.git
git push -u origin main
echo "Done"
Why doesn't this work? What can I do to achieve my goal?
p.s. This is my first script.
You can't push to a repository to github if it doesn't already exist. Usually, you'd create one through a web browser by going on their site, but they released a cli called gh, which allows creating repositories (you have to authenticate somehow before though).

git clone "you appear to have cloned an empty repository" but it's not empty, pull says "couldn't find remote ref master"

I'm trying to set up a vanilla new separate repository for the first time with git 2.37.1 on two W10 systems using drive mapping but I can't find any answered questions that fit my case given my novicitry. :-) Sorry the format is messed up, I did 4 spaces in front of code but most code lines ignore that for some reason.
Spent hours looking at other similar questions, but they all seem to say that there are no commits in the remote repository I'm trying to clone, which is not true. There are lots of commits.
I created a git repository on System1 and it works.
git ls-tree --full-tree --name-only -r HEAD
shows all my files (with lots of commits)
git show HEAD
shows
commit 557...27d (HEAD -> master)
# and the diff between the latest and previous commit
And
git branch -a
shows
* master
No branches, no complexity, no nothing
I go to System2, and create my repo directory, cd into it, then
git init
git remote add origin s:/cap2office # that's my mapped System1 repository)
git pull origin master
I get: fatal: couldn't find remote ref master
git remote
I get: origin
git branch -a
shows nothing
git ls-remote
shows: From s:/cap2office
I also tried:
git clone s:/cap2office
and it says
Cloning into 'cap2office'...
warning: You appear to have cloned an empty repository.
I know I'm missing some trivial magic command, but can't figure out what it is.
You are not cloning a repository, you are trying to clone the working directory of a git clone.
The git repository is stored in the .git folder inside the working directory.
Try this:
git remote add origin s:/cap2office/.git
On system 2, instead of doing git init then git remote add and git pull, do just this:
git clone s:/cap2office/.git
or if you're in Git Bash, sometimes the colon does not work so you need
git clone s/cap2office/.git
Then you can cd to the folder where it was cloned and do the usual git status, git checkout, change stuff, commit, and push to the remote.

Git push error - failed to push some refs to <path>

I am trying to upload my code onto a repository I created on github but I get an error.
Assuming the URL of the repository is https://github.com/a, how do I go about uploading my code to my remote repository?
I tried the following commands on git bash after navigating INSIDE the folder I want to upload -
git init
(output - Reinitializing existing Git repository in C://(path)/.git/
git add.
(blank output)
git commit -m "Initial commit"
(output- On branch main. nothing to commit, working tree clean)
git remote add origin https://github.com/(path).git
(output - error: remote origin already exists)
git push origin master
(output - error:src refspec master does not match any
error failed to push some refs to https://github.com/(path).git)
Why is this happening and what could I do to push my code to my remote git repo? (I want to learn how to use git via cmd)
Thanks for reading my query!
note that you already have an remote repository configured as origin you must remove this configuration or rename then add the correctly repo.
the git command to remove remotes repositories by name is git remote remove ${repo_name}, in your case:
git remote remove origin
the git command to rename remotes repositories is:
git remote rename ${old_repo_name} ${new_repo_name}
then you can add an new remote with the name origin
git remote add origin https://github.com/(path).git
you can assume that the git command git remote add origin https://github.com/(path).git says to git configure an new remote repository into the current local repository, this remote config will "point" to the <URL> and the "alias" of this <URL> will be "origin" (or the name you specify between add and <URL>).
in this case <URL>=https://github.com/(path).git
With this you can have various remotes and specify then when you execute git push ${repo_name}
You can set an "default" upstream for git pull/status with git push -u ${repo_name}
You wrote:
git commit -m "Initial commit"
(output- On branch main. nothing to commit, working tree clean)
git push origin master
(output - error:src refspec master does not match any
Your init created a branch called main but you tried to push master, which doesn't exist. Try pushing main instead.

Laravel - bitbucket pull / push

I'm totally confused how I should add my laravel project to my bitbucket profile and repository. That project that I am adding should be used by me and my college colleagues and they all have to push their changes to the project. How it works ? And how can I pull those changes to my local project on my PC ?
Please help. Thanks!
This can be achieved by creating a repository on bitbucket. Then navigating to the project on your local environment and running the following commands:
cd my-laravel-project
git init
git remote add origin git#bitbucket.org:yourusername/my-laravel-app.git
git add -A
git commit -m "Initial commit"
git push -u origin master
Colleagues can then clone the repository using the following command:
git clone git#bitbucket.org:yourusername/my-laravel-app.git
cd my-laravel-app
after making changes they can be committed using:
git status
git add -A
git commit -m "Fix database connection"
git push
The changes made by colleagues can be retrieved using:
git pull
Merging can be achieved by first pulling the target branch into the current branch then comparing and committing the changes:
git pull origin master
// review the changes
git add -A
git commit -m "Merge changes"
git push

How to publish Github repository

I need to publish a Github repository from a directory on my computer.
I added, committed, and pushed the origin master of the files I wanted to publish from the root directory of my project. By that, I mean I clicked the "create a new repository" button and typed all the git commands in my terminal while in the project directory I want to publish as my repository. For a list of the commands I used, see the below section labeled "Code."
I saw no errors during the terminal commands. When I finished, all I saw in my repository was the README.md file and nothing else.
I tried to check at my terminal to see if my login name matched the Github username of the target repository. But I didn't see any commands for checking the login name at the terminal.
OS/config: Using OS X 10.10.5 (Yosemite) on MacBook Air
Code
I tried this...
git init
git add README.md # This is the problem. (See my answer below.) Should be "git add ."
git commit -m "first commit"
git remote add origin https://github.com/"username"/"repository".git
git push -u origin master
Heres a basic push to GitHub, What kind of errors are you getting?
create a new repository on the command line
git init
git add . //This will add everything in the directory
git commit -m "first commit"
git remote add origin https://github.com/"username"/"repository".git
git push -u origin master
…or push an existing repository from the command line
git remote add origin https://github.com/"username"/"repository".git
git push -u origin master
Here is what solved the problem for me...
That second git command line should be git add . not git add README.md. The . adds all the files in the directory, as mentioned by the accepted answer.
Code
Solution
git init
git add . # This was the key line to change from what was tried in the question.
git commit -m "first commit"
git remote add origin https://github.com/username/repository
git push -u origin master

Resources