How to show history with remote git repository only in JGit - jgit

I only want to run the git log command to get some commit info, and don't want to do it after cloning a remote reprository to local. Wonder if there is quick way for JGit here?

All operations on a Git repository are local. In order to access the history of a repository, you must clone it first.
If you are only interested in the current state you may do a shallow clone to save some bandwidth.

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.

How to sync 2 remotes using Phabricator Diffusion

I have to use 2 remotes for my repositories. For eg.
One is my local git server (gitblit)
One is Github/bitbucket
Additionally, I have to use Phabricator to manage all this. So the workflow i am thinking is:
I push the changes to my local git server, and my friends push to github. Phabricator Observe the changes from local git server + Github and sync it with the other remote changes. I have tried Mirror option, but it deleted the changes from one of remote, because that's what mirror is supposed to do.
So I need to know a way which i can use to sync these 2 remotes using Phabricator.
Apart from creating a (read-only, as you discovered) mirror, Phabricator doesn't really have any ability to push to other servers. It assumes one of the following workflows:
Phabricator is the master copy of the repository - everyone pushes to Phabricator (Phabricator can push to mirrors in this scenario).
Some other server is the master copy of the repository - Phabricator will monitor the remote master and keep a read-only copy of the repository locally.
It might be possible to implement a respository merging task in Harbormaster, but you'll have to be prepared for frequent manual intervention in any workflow that has users pushing to different repositories and expecting automation to sync them together. Probably this syncing task would be easier if you were to get rid of the gitblit server from the equation, and just use Phabricator locally.

Is it possible using git to create a branch for existing files?

This might be a simple question but I have project on git and I am tasked with revamping it. So I started writing a bundle in Symfony which I got at a good state. Is there a way now to make this a branch of git? I probably should have created a branch, deleted everything and then started my project in the empty branch right? So can I do the same now, create a branch, delete all files and just copy my files there? I think as long as they stay in the src folder it should be ok, right?
git checkout -b new_branch_name
A new branch will be created and all your files will be moved there.
This assumes that you have already created a clone to your remote repository and the new_branch_name will be used when pushing.
After this new files can be copied and deleted from where this command was run. Then you must run:
git add *
This will add all files from this folder and subfolder that are to be tracked. Then you must commit them to be maintained in history:
git commit -a -m "Some message saying why you committed them"
Then you can push them to your remote repository:
git push Nameofremote Nameofbranch
In the case above it would be the following assuming you didn't rename remote or switch head:
git push origin new_branch_name
Used This to help me along.

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.

Resources