how to push a single java file to a remote repository - bash

I am new in git and want to push some java files to remote github repository. The files are NOT a project, just some algorithm problems that I want to share on github.
When I tried git push the alert fatal: not a git repository: .git
Is there any quick way to push some/single file to repo using git bash? thanks

One solution would be to do a git init . in the folder whare your files are.
Then add the github repo as a remote:
git remote add origin https://<yourLogin>#github.com/<yourLogin>/<yourRepo>
git add .
git commit -m "My first files"
git push -u origin master
The other approach, especially if the remote repo on GitHub is not empty (because of README and LICENSE files), is to clone that repo:
git clone https://github.com/<yourLogin>/<yourRepo>
cd <yourRepo>
# copy your files there
git add .
git commit -m "My first files"
git push -u origin master

Related

How to commit from a downloaded (.zip) repository?

To deploy my Laravel app to my server, I decided to just download the zip file and unzip it in the folder.
However, I made some changes on my server and I would like to push them to GitHub.
Since there is no .git folder, I don't get how am I supposed to commit the changes or pull from the repository.
Can you help me ?
If you have a repo already that has commits do:
git clone git#REPO_LOCATION_INFO
Check out a new branch on your local:
git checkout -b branch-name
Make your changes, save, add, commit, and push them:
git add .
git commit -m "My commit message"
git push origin branch-name
then open a pull/merge request in your repository and merge to master.
Otherwise you can remote the folder on your local to your repository with:
git remote add origin git#github.com:user/repo_name
and then commit like shown above.
Hope this helps!
I've successfully done that following way:
Rename repo zip downloaded (without .git)
mv repo repo-bak
Clone original repo
git clone <url>
move .git file to zip downloaded repo
mv repo/.git repo-bak
delete cloned repo
rm -rf repo
change the name back to the original
mv repo-bak repo
add, commit and do whatever you want
cd repo && git status

Local repo commit

I have to create 100 repos from my local filesystem. Each project directory has to be created as a separate repo.
I have created separate folders for each of my project and created a base repo on Github. I clone it to my local and tried to do push. However I got all these folders as folder on GitHub.
I need each folder to be a new repo.
Your script it such as, for each folder:
you call the GitHub API to create a new repository
you initialize a new empty repository in the current folder
git init .
git add .
git commit -m "first commit for folder x"`
you define the remote URL, and push
git remote add origin https://github.com/you/folderN
git push -u origin master

GitHub - How to copy from one branch to another

I git cloned one GitHub repo and checked out one branch.
Then made changes to several files.
How to create another branch and push all changes to a new branch (create new branch and push changes to it using terminal commands)?
Assuming you haven't committed anything yet, you can just use checkout -b to create a new branch, then commit your changes:
$ git clone ...
$ git checkout original-branch
(Make changes)
$ git checkout -b new-branch
$ git commit -a -m "Message for changes"
You talked about "pushing changes" to a new branch - the above would commit the changes in the new branch to the local repo. If you wanted to then push that branch back to GitHub, you'd want something like:
# Here origin is the name of the remote to push to, and new-branch is the branch
$ git push origin new-branch
You'd probably want to make sure you were pushing to your fork rather than to the original repo. You can configure each branch to default to a particular remote and branch, and there are various ways of configuring the default push behavior for new branches too via the push.default configuration option. See the git push docs for more details.

clone a fork project in bitbucket

I am new to bitbucket. I am reading bitbucket documentation to learn it. I am at the fork concept. In fork documentation they provide a tutorial how to clone fork repository to my local machine. The tutorial is using the TortoiseHG Workbench. I have forked the external repo to my repo. Now I want to clone my fork repository using git bash because I already clone a git repo. I am unable to clone a fork repo using bit bash. Is fork repo only cloned using TortoiseHG Workbench or there is also a command for cloning.
I am using these commands for cloning my fork repo.
git clone git#bitbucket.org:user/myqoute.git
the error is
conq: not a git repository.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
First, you need to fork (meaning make a clone on the BitBucket side) a Git repository, not a mercurial one like tutorials/tutorials.bitbucket.org.
Use for instance tutorials/online-edit-starter.
Then you can clone that fork with:
git clone https://bitbucket.org/yourUserName/online-edit-starter.git
(using yours BitBucket credentials: username and passwords)
Or:
git clone git#bitbucket.org:yourUserName/online-edit-starter.git
(provided you registered your public ssh key in that repo)
How to clone Repository ? (proposed by Rajesh Chaubey)
First take of fork repository:
git clone https://rajeshchaubey87#bitbucket.org/rajeshchaubey87/uispark.git
(copy your repository url.)
(then go to your master folder).
cd uispark
git remote add upstream https://animatorstar#bitbucket.org/animatorstar/uispark.git
git fetch upstream
git merge upstream/master
git remote -v
git status
git add -A
git commit -m "your comment here"

How to Set Up Xcode with Remote Git Repository

so I just installed a new remote git repository on one of our servers and want to move our old projects there. Our existing projects have local git repositories, and we can add repos from the server, but how do we move our existing projects onto the server?
Any ideas?
You would do these steps:
Make the individual repositories on the server.
git clone --bare nameofrepo
On the actual repo, add the remote to the repository from which you want to send up work:
git remote add origin <url to your remote>
Now push your branch for your work:
git push origin master
Repeat for any other branches you want to have pushed to the central repo.
The URL in the first command can also be a regular file path. Most solutions, however are through an SSH connection.
After creating your Xcode project, cd to that directory
and make sure you are on the master branch
Type:
git remote add origin <URL-of-your-GitHub-repository>
git pull
git branch --set-upstream-to=origin/master master
git merge
git commit -m "Merging with remoteā€
git push
Now your new project has been pushed to the remote GitHub directory.

Resources