Sponsored Content
Top Forums Shell Programming and Scripting Generic script to recursively cd into directories and git pull Post 303002476 by Cows on Friday 25th of August 2017 05:53:51 AM
Old 08-25-2017
Generic script to recursively cd into directories and git pull

Hi all,

I'm trying to write a script to recursively cd into my Git projects and pull them, and will later expand it to build my projects as well.

I'm having a bit of trouble with my current script, as I want to supply a command line argument to tell it which branch to check out. I can hard code it to check out a specific branch but it's failing to take in my arguments.

My current script is:

Code:
#!/bin/bash
BRANCH=$2
echo "Checking out branch $BRANCH"
find . -type d -name .git -exec sh -c 'cd "$1"/../ && pwd && git checkout $BRANCH && git pull; echo "Branch being passed in: $BRANCH' _ '{}' "$BRANCH" \;

A snippet of the output when I run it from the top level of a directory containing many git projects is:

Code:
cows@Whiskey:~/windows/Workspace/git-projects/my-project$ ~/gitupdate.sh _ development
Checking out branch development
/home/cows/windows/Workspace/git-projects/my-project
Your branch is up-to-date with 'origin/master'.
Already up-to-date.
Branch being passed in:

So it looks like the -exec part of the script isn't pulling in my arguments and is just defaulting to the current branch. Any ideas on how to resolve this will be much appreciated. I don't mind if I have to rework how the script works entirely.

The recursive part of the script seems to work fine. If I run the script from ~/windows/Workspace/git-projects, it correctly descends into my-project, my-project-2, my-other-project, etc.

Thanks in advance for any help.

Edit: Fixed formatting. Sorry mods!

Last edited by Cows; 08-25-2017 at 07:07 AM.. Reason: Changed NOPARSE to CODE tags.
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Recursively deleting directories

Say I have a directory call test, and several directories nested in it, and several directories nested in them. And I want to remove all directories within "test" and its subdirectories that have the name "cvs", how can I do this? I tried rm -r cvs, but that only removed the top level direcotry... (4 Replies)
Discussion started by: mikeshank
4 Replies

2. UNIX for Dummies Questions & Answers

How to display directories recursively?

Cannot find how to list the directory structure of a volume recursively. Do not want the files reported. Say I have 100 directories and 10,000 files, I do not want 10,000 lines of output. (If this is relevant, I am using the terminal on my OSX Mac). I hope this is easy - there should be an easy... (5 Replies)
Discussion started by: jwriter
5 Replies

3. UNIX for Advanced & Expert Users

Recursively delete only specified directories with given pattern

Hi All, We have a requirement to recursively delete the directories and its subdirectories older than 60 days based on timestamp (folder creation timestamp)under certain directory. However it has some specific requirements. The directories will continue to be there upto any depth. the... (0 Replies)
Discussion started by: rcvasu
0 Replies

4. UNIX for Dummies Questions & Answers

List directories and sub directories recursively excluding files

Hi, Please help me, how to get all the direcotries, its sub directories and its sub directories recursively, need to exclude all the files in the process. I wanted to disply using a unix command all the directories recursively excluding files. I tried 'ls -FR' but that display files as... (3 Replies)
Discussion started by: pointers
3 Replies

5. UNIX for Advanced & Expert Users

Delete empty directories recursively - HP-UX

Hi, I want to delete all empty directories in a long directore tree structure. I want to use that from a script that will run on HP-UX 11. My definition of empty directory is that there is no regular file under it and directly beneath it. To elaborate, I have below directories. /app/dev/java... (14 Replies)
Discussion started by: asutoshch
14 Replies

6. Shell Programming and Scripting

Recursively rename directories

I have this directory tree under /apps/myapp/data: imageshack.us/photo/my-images/703/foldersc.png How to recursively rename ONLY directories with 5 digits (00000, 00100, 00200,..., 00007, 00107,...)? I want to add to their name two more zeros: Before: 00107 After: 0000107 Thanks in... (2 Replies)
Discussion started by: Susan_45
2 Replies

7. Shell Programming and Scripting

Deleting all files recursively from directories while ignoring one file type

Hi, Seems like I need help again with a problem: I want to delete all files from my lets say "Music" Directory inkluding all of the subfolders except for .mp3 and .MP3 files. I tried it with globalignoring mp3 files, finding and deleting all other files, which resulted in all files... (3 Replies)
Discussion started by: pasc
3 Replies

8. Shell Programming and Scripting

Shell script to copy particular file from directories recursively

I have directory path in which there are several sub directories. In all these sub dir there will be one env.cnf file. I want to copy this env.cnf file from each sub dir's and place them in destination path by creating same filename as sub dir_env.cnf. After copying env.cnf files from source... (4 Replies)
Discussion started by: Optimus81
4 Replies

9. Shell Programming and Scripting

Recursively Searcing file in the directories

i have directory dgf in the dgf( some other Sub-dir are there) 00 01 02 03 04 in all the Sub directory there is a SG.csv .. i want the scripts should run one by one Sub-dir and print the result for that particular Sub-dir ..then go to next Sub-Dir and print the result....... please... (6 Replies)
Discussion started by: Aditya.Gurgaon
6 Replies
GITCVS-MIGRATION(7)						    Git Manual						       GITCVS-MIGRATION(7)

NAME
gitcvs-migration - Git for CVS users SYNOPSIS
git cvsimport * DESCRIPTION
Git differs from CVS in that every working tree contains a repository with a full copy of the project history, and no repository is inherently more important than any other. However, you can emulate the CVS model by designating a single shared repository which people can synchronize with; this document explains how to do that. Some basic familiarity with Git is required. Having gone through gittutorial(7) and gitglossary(7) should be sufficient. DEVELOPING AGAINST A SHARED REPOSITORY
Suppose a shared repository is set up in /pub/repo.git on the host foo.com. Then as an individual committer you can clone the shared repository over ssh with: $ git clone foo.com:/pub/repo.git/ my-project $ cd my-project and hack away. The equivalent of cvs update is $ git pull origin which merges in any work that others might have done since the clone operation. If there are uncommitted changes in your working tree, commit them first before running git pull. Note The pull command knows where to get updates from because of certain configuration variables that were set by the first git clone command; see git config -l and the git-config(1) man page for details. You can update the shared repository with your changes by first committing your changes, and then using the git push command: $ git push origin master to "push" those commits to the shared repository. If someone else has updated the repository more recently, git push, like cvs commit, will complain, in which case you must pull any changes before attempting the push again. In the git push command above we specify the name of the remote branch to update (master). If we leave that out, git push tries to update any branches in the remote repository that have the same name as a branch in the local repository. So the last push can be done with either of: $ git push origin $ git push foo.com:/pub/project.git/ as long as the shared repository does not have any branches other than master. SETTING UP A SHARED REPOSITORY
We assume you have already created a Git repository for your project, possibly created from scratch or from a tarball (see gittutorial(7)), or imported from an already existing CVS repository (see the next section). Assume your existing repo is at /home/alice/myproject. Create a new "bare" repository (a repository without a working tree) and fetch your project into it: $ mkdir /pub/my-repo.git $ cd /pub/my-repo.git $ git --bare init --shared $ git --bare fetch /home/alice/myproject master:master Next, give every team member read/write access to this repository. One easy way to do this is to give all the team members ssh access to the machine where the repository is hosted. If you don't want to give them a full shell on the machine, there is a restricted shell which only allows users to do Git pushes and pulls; see git-shell(1). Put all the committers in the same group, and make the repository writable by that group: $ chgrp -R $group /pub/my-repo.git Make sure committers have a umask of at most 027, so that the directories they create are writable and searchable by other group members. IMPORTING A CVS ARCHIVE
Note These instructions use the git-cvsimport script which ships with git, but other importers may provide better results. See the note in git-cvsimport(1) for other options. First, install version 2.1 or higher of cvsps from https://github.com/andreyvit/cvsps and make sure it is in your path. Then cd to a checked out CVS working directory of the project you are interested in and run git-cvsimport(1): $ git cvsimport -C <destination> <module> This puts a Git archive of the named CVS module in the directory <destination>, which will be created if necessary. The import checks out from CVS every revision of every file. Reportedly cvsimport can average some twenty revisions per second, so for a medium-sized project this should not take more than a couple of minutes. Larger projects or remote repositories may take longer. The main trunk is stored in the Git branch named origin, and additional CVS branches are stored in Git branches with the same names. The most recent version of the main trunk is also left checked out on the master branch, so you can start adding your own changes right away. The import is incremental, so if you call it again next month it will fetch any CVS updates that have been made in the meantime. For this to work, you must not modify the imported branches; instead, create new branches for your own changes, and merge in the imported branches as necessary. If you want a shared repository, you will need to make a bare clone of the imported directory, as described above. Then treat the imported directory as another development clone for purposes of merging incremental imports. ADVANCED SHARED REPOSITORY MANAGEMENT
Git allows you to specify scripts called "hooks" to be run at certain points. You can use these, for example, to send all commits to the shared repository to a mailing list. See githooks(5). You can enforce finer grained permissions using update hooks. See Controlling access to branches using update hooks[1]. PROVIDING CVS ACCESS TO A GIT REPOSITORY
It is also possible to provide true CVS access to a Git repository, so that developers can still use CVS; see git-cvsserver(1) for details. ALTERNATIVE DEVELOPMENT MODELS
CVS users are accustomed to giving a group of developers commit access to a common repository. As we've seen, this is also possible with Git. However, the distributed nature of Git allows other development models, and you may want to first consider whether one of them might be a better fit for your project. For example, you can choose a single person to maintain the project's primary public repository. Other developers then clone this repository and each work in their own clone. When they have a series of changes that they're happy with, they ask the maintainer to pull from the branch containing the changes. The maintainer reviews their changes and pulls them into the primary repository, which other developers pull from as necessary to stay coordinated. The Linux kernel and other projects use variants of this model. With a small group, developers may just pull changes from each other's repositories without the need for a central maintainer. SEE ALSO
gittutorial(7), gittutorial-2(7), gitcore-tutorial(7), gitglossary(7), giteveryday(7), The Git User's Manual[2] GIT
Part of the git(1) suite NOTES
1. Controlling access to branches using update hooks file:///usr/share/doc/git/html/howto/update-hook-example.html 2. The Git User's Manual file:///usr/share/doc/git/html/user-manual.html Git 2.17.1 10/05/2018 GITCVS-MIGRATION(7)
All times are GMT -4. The time now is 03:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy