I copied the android repositories to local pc with repo init and repo sync, the branch is ics_rb7.
In manifest.xml file, revision is ics_rb7.2, that's supposed to mean the branch in each project, right? However, the branch ics_rb7.2 doesn't exist on all projects in the repository. How do we know which branch in the projects is the default cloned one? Thanks,
The branch that you specify in your repo init is the branch to use for the manifest repository only. You can find this repository in .repo/manifests. This branch is not necessarily (or even usually) the same branch that will be used for the individual projects.
The manifest.xml file in .repo is actually a symbolic link to the specific manifest within the manifests repository (use ls -l to see which one). It is created when you do a repo init, using the branch (-b) and manifest (-m) flags that you specified to determine which one to use, or using the defaults (e.g. master and default.xml) if you didn't specify these flags.
The manifest file specifies the default revision for projects using the element, but the individual elements can override this and specify a different revision. This may explain why some of your projects do not have the ics_rb7.2 branch.
If you want to work out what the manifest branch is for a given project, you can either look at the manifest.xml file, or do a git branch -a and look for a branch that looks like this:
remotes/m/my_manifest_branch
Related
I have created a Template Repository in GitHub and then created some repositories based on the template. Since they were created, there have been updates to the template that I want to pull into those repositories.
Is this possible?
On the other repositories you have to add this template repository as a remote.
git remote add template [URL of the template repo]
Then run git fetch to update the changes
git fetch --all
Then is possible to merge another branch from the new remote to your current one.
git merge template/[branch to merge] --allow-unrelated-histories
https://help.github.com/en/articles/adding-a-remote
I will link to the same location as HRK44 but my answer is very different.
https://help.github.com/en/articles/creating-a-repository-from-a-template
Although forks and templates are mentioned in the same section, they are very different.
One of the differences mentioned in the link is:
A new fork includes the entire commit history of the parent repository, while a repository created from a template starts with a single commit.
This basicly means that you will not be able to pull new changes from the template as your git histories are very different and are not based on the same thing.
If you do use the method mentioned in the accepted answer, you will have very hard manual merges that will result in changes to all of the files received from the template, even if they werent changed since the first time you created that repo from that template.
In short, creating a repo from a template (using only master branch) is the same process as:
git clone template
cd folder
rm -rf .git
git init
git remote add origin <new repo url>
git add .
git commit -m "Initial Commit"
git push -u origin master
A few other things that are not (surprisingly) copied when creating a repo from a template:
(Unless github fix this at a later point)
Repo configurations (allowed merge types, permissions etc)
branch rules
So when using this at your organization, make sure to set all repo configurations on the newly created repo.
If you want to merge changes from a template into your project, you're going to need to fetch all of the missing commits from the template, and apply them to your own repo.
To do this, you're going to need to know the exact commit ID that you templated from, and you're going to need to know the commit ID of your first commit.
ORIGINAL_COMMIT_ID=<commit id from original repo you templated from>
YOUR_FIRST_COMMIT=<first commit id in your repo>
YOUR_BRANCH=master
Next you're going to need add the template as a remote, and fetch it.
git remote add upstream git#github.com:whatever/foo.git
git fetch upstream
And finally, you need to rebase all of the commits you're missing onto your branch
git rebase --onto ORIGINAL_COMMIT_ID YOUR_FIRST_COMMIT YOUR_BRANCH
What this is doing it basically creating a branch off of ORIGINAL_COMMIT_ID, then manually applying all of the commits on your original branch, onto this new branch.
This leaves you with what you would have had, if you had forked.
From here, you can git merge upstream/master just as if you had forked.
Once you've completed your merge, you'll need to use git push --force to push all of the changes up to the remote. If you're working with a team, you'll need to coordinate with everyone when doing this, as you're changing the history of the repo.
Note: It's important to note that this is only going to apply to one branch. If you have multiple feature branches, you'll need to perform the same steps to each one.
#daniel's answer also did not work for me because of the unrelated histories problem mentioned in #dima's answer. I achieved the desired functionality by doing the following:
Copy the URL for the template repository you wish to use to create a new repository. (ex: https://github.com/<username>/my-template.git)
Use GitHub Importer to make a new repository based on the template repository.
This solves the unrelated histories problem because it preserves the entire commit history of the template repository.
You need to use the Importer because you cannot fork your own repository. If you want to use someone else's template repository, you can just fork theirs.
Then, add the template repository as a remote.
git remote add template https://github.com/<username>/my-template.git
After you make new commits to the template repository, you can fetch those changes.
git fetch template
Then, merge or rebase. I recommend to merge on public repos and rebase on private repos.
To merge
git checkout <branch-to-merge-to>
git merge template/<branch-to-merge>
To rebase
git checkout <branch-to-merge-to>
git rebase upstream/<branch-to-merge>
NOTE: When rebasing, you must
git push origin <branch-name> --force
in order to override your old commits on your remote branch. This is why I recommend to rebase only on private repos.
I approached this differently as fetch & merge was not ideal as lot of files diverge across template and downstream projects. I only needed the common elements to sync.
lets says we have the below folder structure locally:
repos
├── template_repo
└── downstream_repo
1. Now create a git patch from the parent folder (repos):
git diff --no-index --diff-filter=d --output=upstream_changes.patch -- downstream_repo/some_common_path template_repo/some_common_path
NOTE - the order of the paths matters!, downstream_repo comes first! (interpret this as "what are the changes we need to make to downstream_repo to make it same as template_repo"; look at the --name-status output, it will hopefully make sense.)
--no-index option generates git diff based on filesystem paths. Path can be a single file or a folder.
--diff-filter=d will ignore any files that are in the downstream_repo but not in the template_repo. This only applies when diffing folder paths.
You can use --stat, --name-status to see what the patch will contain.
Review the generated patch.
2. Change to downstream_repo folder and apply the patch
git apply -p2 ../upstream_changes.patch
explanation for -p<n> option from the official doc:
Remove leading path components (separated by slashes) from
traditional diff paths. E.g., with -p2, a patch against a/dir/file
will be applied directly to file. The default is 1.
Using -p2 will drop a/downstream_repo and b/template_repo from the diff paths allowing the patch to apply.
This is the reason for starting with above illustrated folder structure.
Once the patch is applied, rest of the process should be familiar.
All of these options are clearly explained in git diff and git apply official docs.
Another option is to create a patch from the necessary commits and move the patch to a new project
git format-patch -1 HEAD
Insert a patch
git am < file.patch
details are here
I ran into this same issue. I have 10+ projects all created from the same template project (react-kindling) and using git alone wasn't sufficient, as it would pull in changes to the template that I didn't want in my child projects.
I ended up creating an npm utility for updating child projects from template starter projects. You can check it out here:
LockBlocks
It's been a real life saver. Pulling changes from the template is a heck of a lot easier now.
This works too:
git remote add template git#github.com:org/template-repo.git
git fetch --all
git merge template/main --allow-unrelated-histories
I'm wanting to have both a user website and multiple project websites hosted on Github Pages i.e.
username.github.io
username.github.io/project1
username.github.io/project2
I'd like them to share a common set of jekyll files so it's easier to change themes, info, etc.. Has anyone managed to do this? Using subtree / submodule isn't too helpful because you cannot overwrite the source config option to change the location of the jekyll source files. Github Pages always forces the source to be in the root directory. You can change where _includes and _layouts reside but that's not too useful. Any advice or examples?
Use username.github.ui/base as your repository with your base templates. This shouldn't be a gh-page.
This repository should contain a branch with your base templates. For the moment, I say you are using the master branch for that. Branch out and create a project1 and project2 branch in this repo.
Every time you change your base templates, change them in the master branch and then merge the master branch into project1 and project2.
Clone the base repo locally, and add project1 and project2 both as remotes.
Then simply do a git push project1 project1:gh-pages to push your local project1 branch to the first projects gh-pages branch.
This will still multiply the files, but it will mean that you can easily keep them in sync. Changing your base templates would be like this:
git pull project1's gh-pages branch into the base repos project1 branch. Repeat for project2.
Change the base templates in the appropriate branch in the base repo.
Merge the branch into the project1 and project2 branches
git push project1's branch into project1sgh-pages` branch. Repeat for #2.
If you set up some hooks this can be automated fairly easy.
I don't know how to run command line stuff. I just don’t have the environment.
So I'm trying to rename a branch on the GitHub website. It was, by default, named patch-1.
Is it possible to rename it on the site?
I just did it without downloading any code to my laptop and using only the GitHub site.
The solution looks the same as #swcool’s, but I want to add about the default branch.
In my case, the name of the renaming branch did not exist.
Change the default branch (to the old branch you want to rename)
Create a new branch (with a new name)
This action will copy all the contents of the default branch (the branch with the old name) to the new branch (with a new name). At this time, you have two branches with the same code.
Change the default branch (to the new one with a new name)
Delete the old branch
I think you can, just create a new branch with the new name, and delete the old one on github.
More detail you can see here.
It is not possible to rename a branch from the Github website. You will need to do the following -
Setup your Git Environment
Follow this - https://help.github.com/articles/set-up-git
Rename branch locally & on Github
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
If you don't want to install Git, clone the repo, rename the branch locally and push it back to GitHub, you can use the GitHub API for references:
create a new branch where the old one is:
POST /repos/:owner/:repo/git/refs
{
"ref": "refs/heads/newBranchName",
"sha": "<SHA1 of old branch>"
}
delete the old branch:
DELETE /repos/:owner/:repo/git/refs/heads/oldBranchName
That way, you will have "renamed" (create+delete) the branch without having git locally.
And, as commented by user3533716 below, use the GitHub API for listing branches to get those branch SHA1:
GET /repos/:owner/:repo/branches
Since Jan., 19th 2021, you now can rename a branch directly on github.com:
Support for renaming an existing branch:
You can now rename any branch, including the default branch, from the web.
If you've been waiting to rename your default branch from master to main, we now recommend doing so using this feature.
When a branch is renamed:
Open pull requests and draft releases targeting the renamed branch will be retargeted automatically
Branch protection rules that explicitly reference the renamed branch will be updated
Note: admin permissions are required to rename the default branch, but write permissions are sufficient to rename other branches.
To help make the change as seamless as possible for users:
We'll show a notice to contributors, maintainers, and admins on the repository homepage with instructions for updating their local repository
Web requests to the old branch will be redirected
A "moved permanently" HTTP response will be returned to REST API calls
An informational message will be displayed to Git command line users that push to the old branch
This change is one of many changes GitHub is making to support projects and maintainers that want to rename their default branch.
Branch names will not change unless the maintainer explicitly makes the change, however this new rename functionality should dramatically reduce the disruption to projects who do want to change branch names.
To learn more about the change we've made, see github/renaming.
To learn more, see Renaming a branch.
To rename a branch on the Github website, just go to your repo's home page, click on where it says "branches"
Then, find the branch you're interested in, click the pencil button
and from there, you can rename your branch.
If you want a GUI based solution - download the Git Client "GitKraken". It supports doing this from UI by right-clicking on the branch name and choosing "rename [branch name]".
I have a mercurial repository setup with a few named branches. I want to check if a commit occurs into a named branch of a certain name, and then push a copy of the head revision of the named branch to a "publish" folder.
Example: Bobby commits a change to the "Development" branch. The script sees it was commited to the "Development" branch and then checks out Bobby's commit (the latest in the branch) to /publish. If Bobby commits the change to the "Test" branch the copy to publish does not occur.
I have been looking through the documentation, and have been able to have my hooks call an arbritrary bash script on commit, but I am having trouble making use of the variables to handle the above logic, as I am not able to find good documentation on the exposed variables.
Any one able to help me out here?
I managed to get this working by cloning a repository into my publish folder. Then in the .hg/hgrc file for my project:
[hooks]
commit = ./publish projectname
Then for publish:
#!/bin/sh
name=$1
cd /publish/projectname
hg pull
hg update dev
I'm fairly new to github and web development in general. So say I have all of my project files on my Master branch and I want to push only the files needed to make my page run on gh-pages. How would I tell it to only push certain files to the new gh-pages branch? For example, when you use gulp or grunt it makes a folder that is your rendered site for previewing your site. How would I push only the contents from that site folder to gh-pages without adding all of the other unecessary that are on the Master branch?
I've been using Jekyll recently because you can still push all of the files onto gh-pages and it still works. But I have 2 repositories for a lot of my projects. One repository has all of the source files and then the other repository has only the files I need to push a working site onto gh-pages. I want to clean up my github page so it is more organized.
Thank you.
I know this is an old question, but for the benefit of newcomers to Git branches / gh-pages that might stumble across this problem, I found the least complicated way of moving files or folders from a master branch to a gh-pages branch is to do the following.
# First switch to the gh-pages branch
git checkout gh-pages
# Next checkout the specific file you wish to add to the gh-pages branch
git checkout master -- <path/to/file/folders/on/master/branch>
# Perfom the commit
git commit -m "Updated index.html from master"
# And push
git push
Assuming the file(s) you are trying to add to the gh-pages branch exist on the master branch you shouldn't have any problems following the above steps.
If you are using nodejs and npm you can use the gh-pages package from the command line to publish to a gh-pages branch from a specific directory. The gh-pages package has a command line utility.
Installing the package creates a gh-pages command line utility. Run gh-pages --help to see a list of supported options.
Note: You mentioned using Gulp and there is an npm package called gulp-gh-pages that I use successfully to create gulp tasks to put into my deploy workflow.
I believe you're looking for git subtree merge.
The idea of the subtree merge is that you have two projects, and one of the projects maps to a subdirectory of the other one and vice versa.
When you specify a subtree merge, Git is smart enough to figure out that one is a subtree of the other and merge appropriately — it’s pretty amazing.