Git: working with submodules - jenkins

How to configure Jenkins to use git repository with submodules?
I want to build even when change is pushed only to submodule.

There's no direct configuration for this.
Related question here - git plugin and hudson
tl;dr - whenever your submodule has a change (which is of course committed), make sure you make a commit on your main git repository as well to register the git submodule's changes; the build will then kick in accordingly.

Related

Understanding GitHub work flow; what to do after cloning from github?

I am working with RoR, and have recently cloned a project via GitHub. I have a specific RVM gemset for this project, but nothing inside of it. I am not sure if I should create a new branch and then run bundle install, or vice versa. My concern is I do not want to work on the master branch, but I know I need to set up everything first run bundle install.
What is the right method to get started on this project, with out breaking the master?
GitHub is just a hosting for git repositories. Well, writing just is not giving it proper justice.
However you should learn how truly git works. I heartily recommend reading free Git Book.
In short:
git is distributed
you're working only on local working copy
if you don't tell git specifically you want a file to be tracked - it won't (surprise, surprise!).
So running bundle install will not modify what is tracked by git and - specifically - won't affect remote master. It won't modify your master until you modify some files being already tracked. I think bundle install does not. And even then to modify remote master you need to commit and push changes.
You can work on your master. It's safe.
If its someone else's project, or an open-source project, you should Fork the project on Github. Then clone the fork. This will allow you to work on the project, commit your changes locally and push them back to the forked repository.
If it is your own project, and you do indeed want to work in a branch, then clone the repo and make a branch git checkout -b my_branchname. You will then work in the branch, check your code into the branch. Eventually you will want to merge this branch into the master branch. To do this you can merge locally:
git checkout master
git merge my_branchname
Or, you can create a pull request on Github and then merge the branch into master through the Github web UI.
The bundle command, used in conjunction with RVM will just install gems locally, most likely in your home directory (~/.rvm). Gems are not packaged with the rest of the code, so you don't need to fear messing up the master repo.

GIT confusion with restKit

So i am learning to ever so slowly use git to get me the latest update of RestKit as the old version has retain cycles...fair enough HOWEVER, when i pull using the gitHub Client it does not give me the AFNetworking files, which i was then told use the command
git submodule update --init --recursive
which i do, problem is that i noticed that after running that i run
git submodule status
It has taken me off the master branch and put the HEAD back in thus reverting me to old stuff. and hence back to leaks and stuff.
So i thought maybe i could install using cocoapods or perhaps put a submodule within the restkit submodule for AFNetworking...all did not seem to work and now i have followed this guide How do I remove a submodule? up until the last step as i dont know what committing will do? i hope it does not commit the fact that i deleted everything onto the restkit site? i am so confused, initially all i wanted to do was switch the current branch submodule i have to the master.
Assistance would be much appreciated.
EDIT:
Okay as to answer what Commit does, commit only affects your copy of the repository and will in no way affect the remote "main" repository everyone else gets their code from, so in essence i was able to commit it, then run a brand new submodule from the branch i wanted, But the question still remains Is there a way to switch the branch you pull your data from when using the update with --recursive?
Simply go in th e RestKit directory and type:
git pull origin master
(if you use the master branch of course)
Also, if you need to update all your submodules, just go to the root of your project, and type:
git submodule foreach git pull
git submodule update is confusing, here what it really does:
When you invoke git submodule update it looks in the parent repository for a SHA for each submodule, goes into those submodules, and checks out the corresponding SHAs.
As would be the case if you checked out a SHA in a regular repository, this puts the submodule into a detached HEAD state.
EDIT
To switch branch of a submodule simply, let say 'development', simply do in the submodule git checkout development and then you should be able to do git pull origin development

Can't push changes to GitHub

Update: I couldn't get either of the first two solutions provided to work, so I'm providing more detail and setting a bounty.
I have previously forked a github project called Enki (a Rails blogging platform) and then customized it and deployed it on Heroku.
Now I want to start a new Enki blog. I can't fork Enki again, because it's already forked and customized for the first blog. I now cloned it from the author's page, and wanted to add a new repository on my github page so that I could deploy it to Heroku. Here's step by step instructions that I followed
git clone https://github.com/xaviershay/enki.git valentines
cd valentines
git checkout -b myvalentines
bundle install
cp config/database.example.yml config/database.yml
git init
Message
Reinitialized existing Git repository in /Users/mm/Sites/valentines/.git/
1) Why the existing repository? Did I do something wrong? So it's going into the same repository (as the original fork?) even though I've named it something else?
Made code changes then did
git add .
git commit -m "made code changes"
2 files changed, 193 insertions(+), 157 deletions(-)
rewrite Gemfile.lock (70%)
2) Does the fact that it's writing Gemfile.lock mean that it's not changing the branch but rather the master?
Next I created a repository on GitHub
git remote add valentines git#github.com:Username/Valentines.git
git push valentines master
As you can see I, following Ksol's suggestion, used a different word than origin but it didn't work 3) Problem - the GitHub repository 'Valentines' did not show the code changes that I made, but was rather the original gem
Just use another name for your remote than origin?
Adding to #Katen's answer:
You can also use branches for this. For example, your forked repo could contain these branches:
master (pristine code from the author's repo. You may periodically update this)
blog1 (your first blog)
blog2 (your second blog)
This way, to begin working on new installation and customization of this blog engine, just run these commands.
// assuming that you completed and committed your work on a current branch
git checkout master // switch to original code
git checkout -b blog3 // "fork" it to a new branch and switch to that branch
1) git clone will point to the original repository, regardless of the local directory you place it into to. You created a new branch w/ git checkout -b, but it's not a new git repo
2) This looks normal, rewrite is just telling you that you made a lot of changes to that file.
3) I believe this is because you didn't push the new branch to your github page
git push valentines myvalentines
you can also update your .git/config file so origin is your new location. Similarly, there's no reason your master branch need be a copy of the enki master branch, but you should keep a reference to it so you can pull future updates.

Installing rails plugins as git submodules

(Why there is no|Is there a) way to run
./script/plugin install -SOME_HIDDEN_OPTION git://github.com...
So that the plugin is installed as git submodule. The reason for submodules is to keep unrelated code off project's repository.
Perhaps there is a reason not keep plugins as submodules?
./script/plugin install git://github.com/something/something...
Should work without a submodule...
If you want to update the plugin, just navigate into that plugin's folder and do a git pull.
The only advantage of the submodule is that you can see all your submodules from anywhere in the git repository. Otherwise, git just find the nearest git repository and works on that... in te above case, navigating to the plugin's directory will make it the repository you are working on.
Submodules are a bit warty. Also if you clone your repo and one of your submodule remotes is down you're stuck.
I end up tweaking the local code on occasion as well, which necessitates it being in my repo.
Braid makes managing this situation simple.

Where to place Git repository

I just started using Git and I want to know if this is the right way of using it. I started a Rails app with:
rails newapp
Then I did:
cd newapp
git init
git add .
git commit -a
So is it "right" to init my git inside my working directory?
Yes. You can place a git repository anywhere - including the invisible .git directory created by another git repository. I have a friend who has git track all his system config files in case he makes a mistake.
When working on a project, you want to init your repository in the root directory of the project.
To elaborate, each "working copy" of a Git repository is itself a Git repository. If you have a remote copy on a server, that is also a repository. You don't "check out" from there - rather, you "push" your changes and they are merged. If working on a purely personal project, the remote repository is often unnecessary. If you do want to host remotely, Github is a good, free, public choice.
Yep. Looks good to me.
Yes. In a DCVS like git, your working copy is your repository.

Resources