I have a user github.com/userName that has 50+ Repositories that I would like to clone into a single dir on my Windows PC. What would be the best way to do this?
One way would be to create one more repo in which you declare your 50+ repos as submodules.
That way, you would be able to initialize/clone your 50 repos with a
git clone --recursive your_main_parent_repo
(See "How to git clone including submodules?")
Don't forget to commit and push your main_repo when you have committed and push any of your submodules though.
Related
Suppose I have a git repo named waterkingdom It has lot of branches. We will be working with a specific branch called wave-pool.
wave-pool branch has files & folders such as
cost.txt
ride.txt
rules.txt
code/
code/ride.py
code/boom/crash.py
We have another folder which is not a part of the repo named wave-pool-boom
How can I only sync the branch wave-pool from waterkingdom repo to the folder called wave-pool-boom after the commit without knowing the latest commit hash?
Everything is locally on Linux.
How can I only sync the branch wave-pool from waterkingdom repo to the folder called wave-pool-boom after the commit without knowing the latest commit hash??
Everything is locally on LINUX.
Pushing branches from one repo to another is easily done in git, and makes a lot of sense the more you work with git.
Clone waterkingdom into a new directory
git clone --single-branch -b wave-pool /path/to/waterkingdom ~/projects/waterkingdom
cd ~/projects/waterkingdom
Setup a new remote
git remote add r-wave-pool-boom /path/to/wave-pool-boom
Push the branch to the remote (but do not change its tracked remote branch)
git push r-wave-pool-boom wave-pool
Remove the remote (optional)
git remote remove r-wave-pool-boom
Tools to help you further your Git knowledge
git branch -avv
Gives a listing of all branches and what remote branch (if any) they track, what the latest commit hash/message is, and the state (behind, ahead) of each branch.
git remote -v
Give a listing of all the remotes (if any) and their URL's configured for your local repo.
Further comments
Why "without knowing the latest commit hash"? The latest commit hash is always HEAD or <branch-name> or refs/remotes/origin/<branch-name>.
I don't know if this is the right way to accomplish what I need and maybe has also been asked a lot, although I couldn't find a solution.
I have mirrored a repository into my Gitlab account via
git clone --mirror https://github.com/some/repo
git remote rename origin upstream
git remote add origin git#gitlab.com:user/my-repo.git
git push origin --all
Now I want to frequently get the changes from the upstream repository without using git pull or git merge, because I want the commits to be identical to the upstream branch and not "Merging upstream into origin..." commits. From what I understand, you need to
cd my-repo
git remote add https://github.com/some/repo
git checkout branch_name
git pull --rebase upstream branch_name <-- pulls the changes without merging them
git rebase <-- rebases to the fetched changes so my own changes will stay on top
This works if I do it manually for the branch, but if I want to iterate through all branches with. Please correct me if I am approaching this the wrong way!
for branch in $(git for-each-ref --format='%(refname)' refs/remotes/origin); do branch=${branch##*/}; echo "\nUpdating $branch..."; git checkout $branch; git pull --rebase upstream $branch; git rebase; done
it doesn't work and the local branches stay untouched.
I know that Gitlab provides its own mirroring tool, but it is not activated in our company.
This seems to me to be a misunderstanding of what a branch is and what it's for. You should not have any local branches corresponding to the upstream. Just git fetch and stop; you are now mirrored and up to date.
I have an xcode project on my desktop in a directory that originally had a git repository with a tracking branch that tracked a remote branch on github. The remote branch has some 84 commits and is 2 commits ahead of the master branch of the project I'm adding features to. I changed the name of the folder/directory on my desktop. I'm not 100% sure if this is the reason why but when I go to git status I get: fatal: Not a git repository (or any of the parent directories): .git. My plan is to simply git Init, add the remote branch and create a new tracking branch and than commit locally to that branch and than push to the remote branch. However, I'm a git beginner and I'm not sure if this is the proper way to go about it. I'm very weary of losing any commit history or accidentally breaking something. Is the method I outlined a good way of rectifying this loss of the git repo?
If you have all your code updated in remote repo then your local .git is deleted. You don't need to re-init your local repo. Rather just clone it.
git clone remote_repo
If you don't have any commit in remote repo, Simply follow
git init
git add all_local_files
If you have updated remote repo than some commits made in local but not pushed and you lost .git. Simply clone remote. Add all files in a single commit
git clone
git add all_local_files
Looks like you messed up your git repository, but not the code / contents.
One way to restore and keep local changes ( if any ) would be:
Clone another copy of your repo from github.
Copy all modified files to the new repo, omitting removed ones: rsync -duztv /old/local/repo/ /new/local/repo
git status to see what the situation is.
I have following dir stucture
root
root/framework (Yii)
root/protected/messages
All of this folder must be separate git repos
What I want to do is
root and root/framework must be separate repos. But
root/framework must be pull only because I have no push access to this repository. I mean I want to pull yii when I pull parent repo, but don't want to push when I push parent repo.
Another problem is, remote dir structure of Yii (root/framework) looks like http://screencast.com/t/mU1TgXuZDv
I need only framework folder's contents. How can I pull only this folder's contents into root/framework ?
To make root/protected/messages separate git repo so that, when I push & pull root git repo, to do it for this one too. In other words, to push & pull with parent one to 2 separate remotes.
To solve second problem, I initialized new repo inside root/protected/messages but now they push & pull separatelly. I mean, I want them to push & pull changes to/from 2 remotes at once. Can't figure out how to do it.
Also I have no idea about first problem.
Any suggestions?
In order to create a separate and independent git repos within a parent git repo, you want to look into Git Submodules (http://git-scm.com/book/en/Git-Tools-Submodules). These basically allow you to create a completely independent git repos inside a directory which by itself is a git repository.
To create the submodule the command is git submodule add git://path/to/gitname.git folder-containing-the-inner-git. Of course you will need to cd into the parent folder before firing this command, which in your case will be root. The git://path/to/gitname.git will be the git url for Yii and folder-containing-the-inner-git will be root/framework.
In order to pull a specific folder of Yii of the entire git repo you might want to try out git checkout as suggested by this question on stackoverflow How to pull specific directory with git. I have never tried this myself.
Also, as of Git 1.7 you can also do a sparse checkout (https://www.kernel.org/pub/software/scm/git/docs/v1.7.0/git-read-tree.html#_sparse_checkout). Although you will still have to fetch the entire repo.
Once you create a separate git repo using git submodules inside root, you will have to push and pull the git inside root/protected/messages seperately. You can however automate this process by creating a git hook (http://git-scm.com/book/en/Customizing-Git-Git-Hooks) for the repo inside root. A hook is a script that can be executed upon specific git events/operations like committing, merging, etc. For a full list of these events you can refer to this page ... http://www.manpagez.com/man/5/githooks/
It seems that there is no event for a git push or pull. However there is an event for git merge ... post-merge :
This hook is invoked by git merge, which happens when a git pull is
done on a local repository. The hook takes a single parameter, a status
flag specifying whether or not the merge being done was a squash merge.
This hook cannot affect the outcome of git merge and is not executed,
if the merge failed due to conflicts.
This hook can be used in conjunction with a corresponding pre-commit
hook to save and restore any form of metadata associated with the
working tree (eg: permissions/ownership, ACLS, etc). See
contrib/hooks/setgitperms.perl for an example of how to do this.
So you can write a simple bash script like :
cd root/protected/messages
git pull origin master
So everytime you pull from the outer repo in root this script will get fired and you will be able to pull the contents of your inner repo as well. However, this will happen on every merge, not just the merges that happen on a pull so you might want to be careful.
Hope this helps.
You may try more straightforward way:
Init your git repo in root;
Add your root/framework to .gitignore in it;
Go to root/framework and init new git repository there;
You will have matroshka styled repos. But, to be frankly, they will be harder to support than git-submodules solution, since root repo does not aware about other repos at all, and all pushesh, pulls need to be done separately inn each repo.
I have lots of different clones which I work on separately. When I want to update those clones, it can be quite slow to update them from the server. So instead I have a "clean" clone, which I update from the server regularly, and all the other clones clone from the clean clone (hope that makes sense).
But now what I have is a two-step approach. First go to the clean clone and pull, and then go to the real clone i'm working on and pull from the clean clone. Can this be made into 1 step?
Ideally, the "clean" clone would be transparent: when it's pulled from, it would do a pull itself. That way we'd have caching and 1-step. Is there a way to do this?
Keeping a clean clone locally is very common and a good idea in general. I've always stuck with the two step process you describe, but you could do this with hooks if you wanted.
In your cache repos you'd put soemthing like this in the .hg/hgrc file:
[hooks]
preoutgoing = hg pull
which tells that repo to do a hg pull before it bundles up changes in response to a pull or clone request made on it.
Note that even if the downstream (real clone) repo requests a subset of the changesets using pull -r or clone -r this cache repo will pull down everything. That's likely what you want since your goal is a mirror but the commenter points it's worth pointing out.
You can do this using hooks. In your <clean-clone>/.hg/hgrc, add these as a first draft:
[hooks]
# Before a pull from this repository, pull from upstream.
preoutgoing.autopull = [ $HG_SOURCE = 'pull' ] && hg pull
# After a push to this repository, push to upstream.
changegroup.autopush = [ $HG_SOURCE = 'push' ] && hg push
(Note: "autopush" and "autopull" are optional identifiers with no special meaning; you can leave them out if you have no other hooks defined.)