Viewing file from Git using JGIT remotely without creating local repo - jgit

I m writing a web application where it accepts the git URL and file to read and then displays the file on the webpage. I m using JGit for this. I see that JGit needs a local repository to clone before viewing the file. Since this is server, I do not have access to local files. So, is there anyway I can access the git remotely and view the file from there?
Thanks

It's not just JGit that needs a local repository, Git itself requires a local repository. Centralized version control systems like CVS and SVN had remote server viewing built-in, but decentralized systems (such as Git and Mercurial) typically do not.
If you want to browse a Git server, you have to make a local clone, but you could do this in the background for the user.
You might also be interested in the GitHub API, which lets you do what you want, but only for repositories hosted by GitHub.

Related

Remote Go Registry to a self hosted Git repo (not Github/Gitlab/bitbucket)

How can I create a remote repo to a Git server, which is not GitHub, and is hosted on prem (along with Artifactory)?
We currently use Go mod or Glide with "regular" git clone and no Artifactory. In order to make the transition from "regular" to Artifactory smooth, I have to create a remote registry to point to my Git server and setup GOPROXY. Since part of the artifacts will be in Artifactory Go-local and part of them will be in the Git server I might be facing a problem. I think that even JFrog-cli tool will have to make 2 step to pull the data (first with --no-registry and the second "with-registry").
Since the docs explains only how to setup Github and GoCenter remote registries, and I would like to be able to pull code from any other type of git servers as well.

Using GIT to keep operational systems up to date

I'm not a Git novice but also not a guru either and I have a question. We want to create remote repos that appear as folders within our network. The folders will actually contain a large legacy ASP app running in a production manner.
Then we want to be able to make local changes and be able to push commits to these networked repos and thus dynamically update the production application.
We already have the repo on Github and our developers fork that and work locally (we use SmartGit for most day to day stuff).
However (because the app is huge and legacy) we have (prior to using Git) always had a process for copying changed files to the target systems (production, QA etc).
But it dawned on me that we may be able to treat the operational system "as" a repo that's checked out to master. Then (when suitably tested) we want to simply use SmartGit to do a "push to" the operational system and have the changes delivered that way.
I'm at the edge of my Git knowledge though and unsure if this is easy to do or risky.
We don't want to install Git on the operational machine (its restricted to running Windows 2003 - yes I know...) so want to simply treat the remote system just like it was a local folder - with Git installed on our local machines.
Any tips or suggestions?
My tip: don't bother.
You can only push to bare repositories. These are such that they only contain the files normally residing in .git, with no working directory at all. So you cannot "run" those on the server. You would need to push to a bare repos on the server, and then clone/checkout that bare repos into a non-bare local repos on the server itself (which can be done in a post-receive hook inside git). But as you said, you cannot even install git on the server. So git push does nothing for you.
Second option would be to mount the servers filesystem on whatever staging/deployment machine you have, presumably one which you can install git on. Then you can git push into a bare repos on that deployment machine, run git hooks, and copy newly pushed stuff into your non-git server filesystem.
Third option would be to package everything up locally, make a tarball (or, I guess, zip-ball...) and just unpack that on the server.
So. Automated, continuous deployment => great idea. Using git => great idea. Directly using git push, not so much, mainly due to your constraints.

How can I push a repository to my computer and my online server?

I have figured out how to create a repository on github. Now I am trying to push the repository to both my macbook pro and my server, which is hosted through http://namecheap.com, and be able to understand how to keep things simple. I am using wordpress on my server and I have a template theme. I want to edit my files on my mac and then push them to the website, keeping everything easy.
There is plenty of information out there on how to get started with github, so I will just focus on clearing up a misconception:
Now I am trying to push the repository to both my macbook pro and my server
You do not push from github to a server. You need to clone your github repo to your development (macbook) and production (server) environments.
git clone https://github.com/USERNAME/REPOSITORY.git
https://help.github.com/articles/fetching-a-remote/
Alternatively, you can push existing code to an empty repository by initializing locally, setting your remote and then pushing
git init
git add -A
git commit -m "Initial commit"
git remote add origin https://github.com/USERNAME/REPOSITORY.git
git push origin master
Once you have your repo setup, your typical workflow will look something like this:
Make changes in your development environment (macbook).
push those changes to github.
pull those changes from github in your production or staging environment (server).
One of the main things you need to use git this way is access to a terminal on the hosting serve, to push your files directly through git that should be installed as well.
Alternatively you can upload file using any available protocol such as (s)FTP or SSH direct to your server. In this case you'll be using git to version and manager your templates but not to upload or release them.
I've seen that cheapnames.com provides Softaculous as a mechanism to manage their servers. This software also provides synch and install scripts.

R Studio - Cloning local repository

I want to create a master repository on our server, from which I can clone a local version onto my computer.
I am using R Studio v0.98.994.
So far, this is what I have tried doing:
Create a folder for the master repository to live in. I do this using 'new project' in R studio, and tell it to make a git repository.
I can then open up another new project, located on my C drive, and use R studio to clone, by telling it to open an existing project and setting the URL as the location of the master project.
However, then when I make changes and commit to my local repository (which works fine) I cannot push to the master repository, I get an error exactly as described in this question: git push fails: `refusing to update checked out branch: refs/heads/master`
So it appears that R Studio creates non-bare repositories?
Now I thought, well okay, I will use git bash to initialise the repository and then connect to that within R studio.
I do so, but cannot then find a way to use that repository in R Studio.
I am very new to Git, so it is entirely probable that this is one of those 'read the instructions' questions, in which case I am very sorry - and could someone possibly point me towards some guidance for this situation? I have spent the better half of a day googling around this error and haven't yet managed to pull together the pieces :( I also apologise; this doesn't feel like a very reproducible question.
It sounds like you are using Windows Git, with a setup on a local Windows machine (C: drive) and a server of some kind, mounted as the S: drive. There's a few things you should be aware of when doing this.
Shared Repositories
If you are intending for multiple people to share the same repository, you want to initiate a shared repository. See the --shared option in git-init for more details. Note that I'm not sure how having your repository on a Windows machine affects the sharing options. If you are just trying to keep your repository in two places, that makes things a lot easier.
Bare Repositories
Separate from the discussion of sharing is the discussion of bare repositories. If you don't intend to ever work with files in the server (i.e. it's just going to be a place to push changes so they are safely stored), you could initialize a bare repository. A bare repository contains the database structure of Git, but does not have the actual files in the directory.
A standard Git repository is a directory with a hidden folder in it named .git. This .git folder contains all the various data structures that Git uses to track changes. A bare repository is essentially a folder containing only the contents of .git.
The good thing about a bare repository is that no one can work in the repository itself (since there is no working directory, just the database). This means that no one could log into S: and edit the repository themselves. Instead, they would have to clone the repository, then push their changes back to the origin. The GitGuys have a good article about why this is ideal.
Note that shared repos and bare repos are not dependent or mutually exclusive. As a general practice, if you are having a "server repo" from which you pull and to which you push, you should have it be bare, regardless of whether the project is shared.
A Non-Shared Workflow
Since it's not clear if you are sharing or not sharing and you're on a Windows environment, which I don't know about from a sharing standpoint, I'm going to give you a simple example. Using git-bash, you should be able to change directories to wherever on S: you have your repositories. Then, use git init with the bare options as described by the link above to initialize a bare repository. Navigate to where you want your repository to live on C:, and then do git clone to get a working copy.
Add a README file or something else so you can do your initial commit, and then commit and do git push origin master to push your changes to the S: repository. Once all that is done, THEN initialize the RStudio Git project. RStudio should defer to your existing configuration, and things should hopefully work.

Manage wordpress blog on remote server via git

I want to be able to develop my plugins & themes on my machine and the changes be reflected on my server almost instantly. Also I want a backup plan. So git & github seems a very good solution. I want to make regular changes to the server (push from local) and once in a while upload them on github too (local to github or remote to github).
The question is can I clone the repo from github to my remote server and to my local machine and be able to push from local to remote or pull from github to remote (if I'm not at home)?
Edit: I did a research and I found out that I actually need a bare repo in the server, but i want it to be able to push/pull to/from github.
In github and bitbucket (https://bitbucket.org) you can add any number of ssh keys from different machines and push and pull from anywhere you want. The command to generate such a key is
ssh-keygen
answer the questions with enter and the ssh key will be in /home/user/.ssh/id_rsa.pub. You have to do this for every machine you want to push and when the repository is set to private, yo also have to do it for those machines, you want to pull from.
So the workflow would be
editing locally
pushing to github/butbucket repo: git push -u origin
log in to the machine where wordpress is running: git pull

Resources