How to push a project folder from IDEA to Github repository - java

I have a clean Github repository. If I initiate a local Git repo and do Initital commit and then do the following:
git remote add origin https://github.com/kirill-ch/my-repo.git
git push -u origin master
then I get there my project files - the /scr/ folder and pom.xml.
I would like to have a folder in my repository in which I can hold my project so that I can commit different projects in different folders in the future.
How can I do these from the command line or from IDEA?
I have seen the question: Adding a folder from local machine to github
however I don't understand what there going on.

1. If the folder you want is not yet being tracked by git
Just place your folder with the data in your repository root directory and then add the changes and commit.
Move the files to a new directory in your repository root directory.
If you run git status you should now see a list of all the files you have added to your repository.
In the command line, locate to your repository root directory and then run git add ..
Commit the changes: git commit -m "Your commit message".
Push your changes: git push.
Note that git does not know anything about directories/folders, so you cannot add an empty directory in your git repository, git won't find it.
2. The folder/files are already being tracked by git
You can move your /src/ and pom.xml to another directory say test by running the following command (assuming those files are already being tracked by git):
git mv src test
git mv pom.xml test
These will allow git know that you have moved your files to another directory so you now just need to commit and push the changes to the remote repo.
Please note that you cannot have a single local git repo with different multiple remote repos for different directories in your local repo. What you can do instead, is to have multiple local git repos with each having their corresponding remote repos and just house all of them under a single directory on your system (not git directory, just a normal directory).

Related

Hosting executable .jar files in BitBucket repo or automate packaging executable .jar files from git into local folder

I am trying to create a launcher application in Java that can invoke executable .jar files. An easy way for this is to host the executable .jar files in a cloud instance and the launcher application would just download the .jar files from there into the user's local folder. The dilemma is the absence of the cloud service or a server that can host the jar files.
As a workaround, I thought I can just host the jar files in BitBucket and that is where the launcher application will download the executable files from. Though, I think this is a little unconventional since it is mostly used to version source codes (please correct me if I am wrong). Also, I am not sure if it would be possible to invoke FTP or download files from there (perhaps through BitBucket API, maybe?).
Another option is that it could be possible to make the launcher app to create executable jar files from the git repo and download the package executable jar files into the user's folder and invoke from there. If this is possible, I would appreciate any leads towards this option.
Thanks!
yes you can push your binaries to github (getting raw content is difficult from bitbuket your request need to have authentication and stuff).
here is how to for that
copying here as well in case get's removed.
How to create a maven repository for your github project step by step
Clone your project in a separate folder
(note: replace ORGANIZATION and PROJECT)
git clone git clone git#github.com:ORGANIZATION/PROJECT.git my-repository
cd into it
cd my-repository
Create a new branch (here named repository)
git branch repository
Switch to that branch
git checkout repository
Remove all files
rm -rf file1 file2 file3 .. etc
Install your jar in that directory
(note: replace YOUR_GROUP, YOUR_ARTIFACT, YOUR_VERSION and YOUR_JAR_FILE)
mvn install:install-file -DgroupId=YOUR_GROUP -DartifactId=YOUR_ARTIFACT -Dversion=YOUR_VERSION -Dfile=YOUR_JAR_FILE -Dpackaging=jar -DgeneratePom=true -DlocalRepositoryPath=. -DcreateChecksum=true
YOUR_JAR_FILE should point to an existent jar file, this is why it's best to create your repository branch in a different folder, so you can reference the existing jar in /your/project/path/target/artifact-x.y.z.jar
Add all generated files, commit and push
git add -A . && git commit -m "released version X.Y.Z"
git push origin repository
Reference your jar from a different project
The repository url you just created is > https://raw.github.com/YOUR_ORGANIZATION/YOUR_ARTIFACT/repository/
2nd option is also a good approach as you user will get always the updated content but that will add building time into it, depends on your use case.
In general, it's not a good idea to store build products in a Git repository. Generally build products are large, tend to compress poorly (especially JAR files, which are already compressed), and don't need to be versioned. This is exactly the behavior you don't want from your Git repository.
While you can indeed do this, you're likely going to find that Bitbucket is not going to want to host your Git repository for this purpose, and then you'll have to find an alternative solution. You'd be better off hosting these assets in a cloud storage bucket or even on a static server and downloading using HTTPS. If this isn't achievable, you need to consider why that is, and look into solving it.
If these JAR files are build products for a release of software you're already hosting on Bitbucket, then it's probably fine to use the standard release asset functionality of Bitbucket for that purpose. You just don't want to use a Git repository, which is significantly more expensive to serve than static assets.
You also don't want to use FTP because (a) it's slower than HTTPS and (b) due to people not complying with the spec, it's impossible to use TLS with it consistently. Your software will have an exploitable security bug if you download data over an unencrypted connection without integrity checking and then execute that data.

how to remove unwanted files from maven project

I am currently working with a spring web project. In my project, i am using git,maven and eclipse as IDE. when viewing git status in terminal these three files are present in all cases:
.classpath
.gitignore
.settings
how can in remove these unwanted files. i have no idea how these present in my project. my colleagues have also experiencing this issue.
any suggestions will be helpful.
As its a git repository, you can include below lines in your .gitignore file and then commit your .gitignore file to your central git repository, after that your local git repository won't show the ignore files which you added.
.settings
.classpath
Read more about .gitignore here https://help.github.com/articles/ignoring-files/.
Edit :- You these files are already unchecked then you need to run below command (If you already have a file checked in, and you want to ignore it, Git will not ignore the file if you add a rule later. In those cases, you must untrack the file first, by running the following command in your terminal:) :-
git rm --cached FILENAME
So in you case above command will look like git rm --cached .classpath and git rm --cached .settings.
Create .gitignore file in your project root directory and specify file path you want to untrack, for example:
.classpath
.project
.settings
target/
.mvn/
As other guys mentioned - you should add .gitignore file to the root of the project. There is a good Github project - gitignore. You could concat this files into one:
Java.gitignore
Maven.gitignore
Eclipse.gitignore
You could read more about .gitignore in a project description
You can directly open your workspace and open your project, after that you can manually delete those files... Make sure you check "show hidden files" if you are using windows and before deleting please close eclipse and then remove the files.
In SVN Repository can use Add to svn:ignore. using this one can remove unwanted files.

Add .jar files into a git repository

I have a project on eclipse where recently i created a new folder called lib and added some .jar files inside.
I cannot seem to commit the changes to git. It just doesnt appear in the tracked list of files..
I have removed .jar from .gitignore in my branch and commited the changes, and still the same.
The way I got it working for me was -
git add --force /path/to/the/NAME_Of_THE_JAR.jar
in the .gitignore file present in your project, you need to make sure that you allow *.jar files to be pushed. In my case, *.jar files was listed in ignore list. So I removed it from that list and git was able to detect it and I was able to push it.
You put your files in the project package, but you didn't put them under version control. All you need is to add them to VCS by "git add" command. Here is good documentation.
You should use this command in git bash or in terminal (if you have added git to path)
Also I recommend you to use build manager as Maven, Gradle or Ant to add you dependencies. Good luck!
You can identify if your .jar is needed to be added using the command git diff, git will indicate if you need to add the files to your repository.
Them use git add . and your files will be available for commit.
If the lib folder is ignored by .gitignore you can force adding them to the VCS using the following command:
git add /path/to/lib -f

Egit: Set gitignore to ignore all eclipse project files

I have a project up on github and I want to remove all eclipse related files from it and allow people who clone it to use any ide they want. Here is the project: https://github.com/vedi0boy/Archipelo
What would I have to put in my gitignore? I'm still very new to the whole version control manager thing so you don't have to tell me exactly what to put but maybe explain how it works and what to be careful about so that it will still work.
By the way, it uses gradle so I would also like it so that the gradle related files remain untouched since cloners will need them to build the project and I plan to remove 'APIs' folder and just use gradle dependencies.
For excluding configuration files you have to configure .gitignore to something as follows:
# Eclipse
.classpath
.project
.settings/
# Intellij
.idea/
*.iml
*.iws
# Mac
.DS_Store
# Maven
log/
target/
And, only after this, you have to push your project because now you have to push your configuration to the remote repo.
And you can not delete it locally and push. You have to delete it from remote repo only:
git rm --cached .project
For a directory:
git rm --cached -r target
One of my .gitignore files looks like this:
/bin
/.classpath
/.project
/.settings
/target
You can look at other projects at e.g. GitHub to let you inspire what you might want to put into your .gitignore, e.g.:
https://github.com/spring-projects/spring-framework/blob/master/.gitignore
https://github.com/spring-projects/spring-social/blob/master/.gitignore
However, I think my example above should be sufficient to start with.
Add all the eclipse files to the .gitignore and, to remove them from the remote repository, you will have to
git rm (-r) --cached eclipseProjectFile
The above command will remove the file from the repo, but not from your machine.
1 - create .gitignore file on your GIT project root direcotry (where you have typed "git init" (near .git directory) ). With content of nazar_art noticed or you can add some other pattern for ignore.
2 - git rm -r --cached file_1 file_n directory_1 directory_n ...
3 - git commit -m "removed some files and directories from remote repo and created gitignore :))"
4 - git push -u origin --all (this will synch all branch of your remote (origin) repo) or you can type git push [remote] [branch]
i know it is late. but may be helpful somebody who just beginning
This is general answer to ignore any file extension from git staging.
In Eclipse go to windows->preferences->git->ignore resources (you can simply search "ignore resources").
Check any class extensions that you want to avoid staging in git staging area.
If you do not find your extension there, you have the option to add any extension that you need to ignore.

project name doesn't change on the remote repository after renaming from eclipse

I'm using EGit with eclipse Mars. I have renamed some classes included the project name. When I push the commits to the remote repo., I can see the file names have been changed but the project name is unchanged.
So now I have the new project name on my eclipse but the old project name on the remote repository on GitHub. How can I see the name change on the remote repository?
EDIT
.project file, both locally and remote, has the updated name.
Eclipse keeps the name of the project name in the .project file and I suspect that is getting properly modified. If you want to change the folder name in the repository, you may have to fall back to git command line.
If by project name you mean the github repo name, that one wouldn't change.
An eclipse project name is recorded in the .project: if that file isn't ignored locally, the .project in your github repo should reflect the new name. Check the output of git check-ignore -v -- .project.
.project files on both local and remote repos have the new name
That means the rename has succeeded.
If you want to see your project locally under a folder named after your project, you would need to:
delete your current project from the Eclipse workspace (simple delete, keeping the data on the disk),
close eclipse
rename the folder
open eclipse
import the project into your Eclipse workspace.

Categories

Resources