Git: How to clone project without losing the current branches? - java

I have a project in my local Git repository and there is a problem in the project that is not fixed after lots of pull from origin etc. So, I need to clone the project from origin without losing the branches in the project (in local repository). So, what is the best approach for this kind of situations? Because sometimes I have seen this problem and fix the problem by deleting project completely on local repo and cloning from remote repo.

You shouldn't have to delete a project completely on your local repo just to clone from the remote repo. If you really want to do that you could just try creating a new local repo and then clone from the remote repo and then you will still have all of your other branches in the original local repo.
I would recommend trying git reset --hard origin/master to see if that fixes your problem.

Related

Cannot create a pull request when pushed from the local git to github

I faced a problem when making a pull request on Github.
I created a new GitHub repository for my new project. It is done by using the NetBeans IDE. When I was finished with my project, I committed it to local git and pushed it to the github repository that I had previously created via a separate branch. But when I'm going to make a pull request to merge that branch with the main branch, it says, "There isn't anything to compare. "Main and master are entirely different commit histories."
Note: When it is pushed there was only the ReadMe file in the Github repository.
How to resolve this problem?

GIT - Unable to revert the project state to specific revision in History

I justed messed up my GIT Remote Repository and Local repository by updating the current code with older commit using git checkout <revision-no>.
Assume that I am at commit state A-B-C-D and I want to revert the complete project state to B, which means I want same package structure and files as it was pushed to B. Is there a way to do this?
I tried git reset --hard HEAD, unfortunately I am still seeing files committed at level D in my local repository and remote repository.
Maybe you are in a "detached state" since you did a git checkout {commitId}.
This may work:
git checkout master and then
git reset --hard {commitId of B}
In general, git checkout is for updating(reverting) the local working files and modifying the position of the HEAD pointer. It can be used for looking at previous commits and switching branches without actually changing anything in the project. git reset is for actually modifying a branch pointer to revert a project branch to an earlier commit. At this point, your HEAD is still pointing to an earlier commit. So you need to set it back to end of the current branch:
git checkout <branch name>

Always using remote repository in egit

I have gone thru the egit tutorial doc here http://wiki.eclipse.org/EGit/User_Guide.
I now have a git repository with an eclipse project on my laptop and can push this to a remote git repository on git hub. However, this means I have two git repositories - one local and one remote. I'm thinking I'd prefer to just use the remote one only. This would mean any time I commit, it commits to the remote and there is no local repository.
Is it possible to this egit?
Thanks.
git is a distributed version control system. By definition this means that each developer has its own repository.
I have not experience with egit but you can configure a hook to automatically make a push after a commit.
Also, in a git cli you could set an alias to make the commit and push process in only one step, but anyway, the local repository will be need.
You should always have a local repository to work with. First pull the repository to local repository, perform changes and push back to the remote repository.

Is there a way to disable the local maven repository?

This may sound crazy but we have our developers all working on the same Linux machine, this machine also has nexus installed as our maven repo. Effectively everyone ends up with artefacts in their ~/.m2/ folder which are also duplicated in the nexus server.
Is it possible to simply tell maven to only look at the artefacts in nexus?
I have for the moment set the property <localRepository>/path/to/global/repo</localRepository> in our global maven config, but unsure if this could cause a problem if two users are grabbing the same file at the same time.
We do this because the company won't buy us powerful workstations so we all ssh to our development server.
I'm not sure if this directly answers your concern, but it looks like what you're doing is correct.
From http://maven.apache.org/settings.html
localRepository: This value is the path of this build system's local
repository. The default value is
${user.home}/.m2/repository. This
element is especially useful for a
main build server allowing all
logged-in users to build from a common
local repository.
I wouldn't want to point my local repo to the nexus datastore, because then installs would update the repository datastore behind nexus' back.
However you could set up a single "machine" local repo separate to the nexus datastore,
and then for each user change the ~/.m2/repository directory to be a symlink pointing to the "machine" local repo.
At least then you'll only have 2 copies of the repo.
Concurrent installs and downloads, are still likely to clobber one another, but this can be fixed with an annoying redo.
Update:
There is a new solution available.
Installation of the TEAM (Takari Extensions for Apache Maven) extensions, provides a thread-safe local repository and an improved algorithm for multi module builds.
See http://takari.io/book/30-team-maven.html#concurrent-safe-local-repository
Use the
--offline
option at command line.

Most robust way to convert a CVS repository containing Eclipse projects to git?

I have a situation where I have an elderly CVS repository which we would like to convert to git once and for all while keeping full history etc.
All folders at the root of the repository contains Eclipse projects (either plain or dynamic web projects) including .classpath and .project. We use Team ProjectSets to check out the projects we need for a given task (where the project set is located in the project containing the main, and the rest are library projects).
When the Team ProjectSet is checked out, the workspace is fully populated.
This approach has worked pretty well for many years (except the project set part which came with 3.5), and we would like to work in a similar way with git if possible, but we are uncertain how.
I've played somewhat with git cvs import but it failed - probably due to us not using modules.
How would you suggest we do this, and how should we work with git to allow our current usage of shared library projects? Would we HAVE to introduce maven and create maven modules for our library projects? Or just ant ivy?
EDIT: I've now managed to convert our CVS repository to Subversion with a suitable cvs2svn invocation and found that Eclipse recognizes the resulting Subversion repository nicely. Unfortunately after cloning http://github.com/iteman/svn2git` and trying to run bin/svn2git I get
tra#Sandbox:~/cvsgit/svn2git/svn2git$ bin/svn2git
bin/svn2git:35:in `initialize': wrong number of arguments (2 for 1) (ArgumentError)
from bin/svn2git:35:in `new'
from bin/svn2git:35
This is with Ubuntu 10.04.1 LTS Server and I've tried various sudo things with Ruby and its gems without fully understanding what I did as I am not a Ruby programmer so I may have messed up things a bit. I'd appreciate advice - if the easiest is to install another Linux variant to do the conversion, that is fine.
EDIT:
https://help.ubuntu.com/community/Git
http://css.dzone.com/articles/subversion-git-morning
Edit: My first try with the default svn2git completed successfully (after a while), and I get a nice repository where git branch -a reports roughly
tra#Sandbox:~/gitroot/svnroot$ git branch -a
* master
remotes/XX64_DEPLOYED_CODE
remotes/Beta1
remotes/Beta2
remotes/SV46
... lots more
We are interested in being able to check out the SV46 branch and work with it (we basically do not care about the tags, just actual branches). I have set up gitosis and pushed this repository to gitosis, and cloned it to another computer to find out how to do the "work with SV46" bit with Eclipse. THAT repository does not know of all the branches:
tra#TRA ~/git/git00 (master)
$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
Do I need to massage the original result from svn2git to get the information into the gitosis repository? Do I need to clone with an argument? Should I redo the svn2git step with the suggested version instead of the one shipping with Ubuntu?
EDIT: It turned out that publishing the svn2git generated repository with "git push --mirror" made things shown up in the gitosis repository. I now see the following inside gitosis (trimmed):
tra#Sandbox:/srv/gitosis/repositories/git01.git$ git branch -a
* master
remotes/XX64_DEPLOYED_CODE
remotes/Basic_Beta1
remotes/Beta1
remotes/Beta2
remotes/SV46
... lots more
tra#Sandbox:/srv/gitosis/repositories/git01.git$ git branch
* master
tra#Sandbox:/srv/gitosis/repositories/git01.git$ git tag -l
tra#Sandbox:/srv/gitosis/repositories/git01.git$
Trying to clone this repository with git clone gitosis#sandbox:git01 -b remotes/SV46 or git clone gitosis#sandbox:git01 -b SV46 both tell me that the remote branch is not found upstream origin, using HEAD instead.
Am I barking up the wrong tree?
First of all, using submodules for independent parts of your Central VCS repository (i.e. your CVS repo) is always good (see "What are the Git limits?").
That mean you will end up with many independent Git repo, that is "set of files evolving independently one from another", which is why submodules exist.
So multiple Git import (in multiple repo) are required.
But since git cvs import is not always up to the task, I would recommend:
cvs2svn in order to get an SVN repo first (just one repo)
svn2git in order to properly convert your SVN repo to a git one (i.e. transforming SVN branches into Git branch and SVN tags into Git tags)

Categories