how to 'go get' files in a different branch in github repo other than master - go

I need to go get following files from this repo
go get github.com/mattes/migrate/driver/mysql
but those files are in a different branch, not in master. How can I go get those files? I tried following way but it didn't get those files that I need.
go get gopkg.in/mattes/migrate.v1
Appreciate any help.

This is not supported by go get, you need to download the files manually to your GOPATH or to your vendor/ folder.
A vendor solution:
git clone git#github.com:mattes/migrate.git
vendor/github.com/mattes/migrate;
cd vendor/github.com/mattes/migrate;
git checkout BRANCH_NAME;

Related

Issues with 'go build' on forked repository

I build a binary file for a GitHub repo (go code), which works fine. no issues.
I forked that repo, and modified a single line in the HTML file that has nothing to do with GO code, built the binary file for the new forked repo but the binary it generates refers to the original repo code, can't understand why.
I even cleaned all the code using go clean -i all command and manually removed all the installed code, binary files from $home/go/bin and the repo directory, but it still refers to the original repo code instead of new forked code.
Based on the solution suggested by Tobias, I performed the following steps:
After that, I executed go build in that repo directory, but the new binary file still refers to the old code. I even removed the old binary file and generated a new one.
That's a common problem in go. The references system in "location based" so it searches for these files in the "correct" path. Idk if go modules fix this issue, but atleast when not using go modules you'll have to work around it.
You can solve it by
Solution 1
Download the original repository you forked by:
go get http://github.com/awesome-org/tool
Add your fork as remote
git remote add awesome-you-fork http://github.com/awesome-you/tool
You'll have to make changes in the folder of the original downloaded repo and Push and Pull to/from your fork.
git pull --rebase awesome-you-fork
git push awesome-you-fork
Solution 2
Work around go get:
You create the path the original repo would have, but clone your own fork into it. That way you can push & pull to your fork. That may be the better solution
cd $GOPATH
mkdir -p {src,bin,pkg}
mkdir -p src/github.com/awesome-org/
cd src/github.com/awesome-org/
git clone git#github.com:awesome-you/tool.git # OR: git clone https://github.com/awesome-you/tool.git
cd tool/
go get ./...
These Solutions were found here: http://code.openark.org/blog/development/forking-golang-repositories-on-github-and-managing-the-import-path
The problem with a forked copy of a go packages is when the package is really multiple go packages in one repo, the import statements refer to original base repo, ie: github.com/orig/repo.
This is not an issue for repos with only one go package as it never refers to itself.
But if it has multiple, ie: package github.com/orig/repo/A imports github.com/orig/repo/B
And then you fork it as: github.com/fork/repo
Then when the go compiler sees import "github.com/orig/repo/B" in the source, it goes to download the original version and not your fork.
Fortunately, go modules solves this.
Basically, create a go.mod at the top of your forked repo and add:
module github.com/orig/repo
then, the go compiler will assume that you are "orig/repo" regardless of where you actually are checked out from.
so, when orig/repo/A imports orig/repo/B, it will look locally.
If there are other imports you need to override that are outside the main forked repo, you can also force dependencies to come from another place using replace
SOLVED
At first I thought it was problem with a FORK (which is a common problem experienced with fork of Go language repo's), but it turns out, it was Repo specific problem.
One of the dependent libraries had to be reinstalled for the forked repo to work, which was not mentioned in the Original repo docs.
Finally, this link helped: https://github.com/inconshreveable/ngrok/issues/181#issuecomment-65646229, the problem was not generic but repo specific
I followed the below steps from above link to resolve the dependency on go-bindata
go get github.com/jteeuwen/go-bindata
cd $GOPATH/src/github.com/jteeuwen/go-bindata/go-bindata
go build

Git giving warning: unable to rmdir

I am using git bash on windows 10 which was recently updated to creators update.
whenever i am trying to switch between branches i get following thing
$ git fetch && git checkout master
warning: unable to rmdir Ionic_Developemnt: Directory not empty
Checking out files: 100% (6312/6312), done.
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
I don't know why this is happening also there is a .git hidden folder in the Ionic_Development folder
Can anyone help with this why so error _/_
warning: unable to rmdir on git checkout means that you're switching to a branch where this directory doesn't exist; git tries to remove it but there are some temporary files that git cannot remove; the directory is not empty so git cannot remove it also, hence the warning.
This happens mostly when your files are still in use. I personally experienced this sometimes with atom editor. Try to close your editor, and maybe any running compilers that are watching for changes too, and try to checkout again.
Found the answer, instead of git checkout, use git checkout --recurse-submodules.
Use git config submodule.recurse true to tell git always use --recurse-submodules (only in git versions 2.14+), add --local if you want that only in local project level.
Reason:
This issue happens on (Git < 2.13) when git checkout could not take care of those submodules correctly.
Reference: https://github.com/gitextensions/gitextensions/issues/2966#issuecomment-622666568
Original Answer
Actually I think this answer is partially right :O
If a folder is tracked by local .git within that folder, it would be changed according to .git when you switch branches (e.g. deleted from our point of view, if the other branch does not have this folder).
If a folder is ignored by .gitignore, the folder would be left unchanged when you switch branches.
However, if the folder is a submodule, which is tracked by submodule .git, local .git would try use rmdir when switching branches, which caused the problem.
I know this is old, but in case anyone stumbles on this, as I did, it can also be that you're switching to a different branch and you have a Git submodule. Look for the .git hidden folder in the directory, you can delete it if you don't need it to be a submodule--just be sure to commit the folder to the parent repo in the current branch before switching.
rm -r .git

how to update the vendor folder for https://github.com/hashicorp/terraform.git for terraform

Hi i am following steps given for hashicorp/terraform and performed below activity
# Get latest master branch's dependencies staged in local $GOPATH
git checkout master
git pull
godep restore -v
# Make your way to the dependency in question and checkout the target ref
pushd $GOPATH/src/github.com/some/dependency
git checkout [latest]
# Head back to Terraform on a feature branch and update the dependncy to the
# version currently in your $GOPATH
popd
git checkout my-feature-branch
godep update github.com/...
after this i can see my Godep.json file has been updated however i dont see changes in the vendor folder . it still points to old. Well i am looking emr support from vendor for that i am updating go-aws-sdk which is available with the latest go-aws-sdk. when i called go update github.com/... it has modified the godep.json but not vendor folder .
Could somebody please let me know the reason. Thanks
You have to do a godep restore -v again. update only updates the dependency in the Godep.json file.

Cannot PUSH recent commits to Github that have been pushed to Bitbucket

I have two remote repositories. One is private (Bitbucket) and the other public (Github). I had been pushing changes to Bitbucket using Github app and then pushing the same commit to Github repo using Xcode. However, recently I have been unable to PUSH the commits to Github and using SourceTree I get this error message:
This repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/pre-push.
This is how it looks from within SourceTree:
How can I get my Github repo to accept the most recent commits?
You have a pre-push hook which is telling you that you have git-lfs (large file support) enabled for this repository, but that it can't find the git-lfs program on your computer. The solution is to either remove the hook (which is located in .git/hooks/pre-push, as the error message says), or to fix your PATH so that it can find the git-lfs program.
It would have been enough to say that the .git directory is in the original local directory of your repository and you probably need a program like TextWrangler or similar, that shows the hidden files starting with a dot, to be able to see it and delete it by moving it to the trash (right click mouse). It took me one hour to figure out this. I hope no one else have to waste that time.
Here is the instructions for removing the pre-push file using Mac Terminal:
First: cd to the directory that is your local repository for your project. (The main folder that holds .xcodeproj and other files) The .git file is hidden but you can still access it by typing cd .git/hooks in terminal. If you type ls in terminal to view all files within the current directory, you'll notice the pre-push file. Type rm pre-push to remove the file. You should now be able to push to your remote repository. Just be sure to cd .. back a few times to your local directory for your project. Simple as that.

How to restore version control in XCode?

I have just recently backed-up my XCode C++ project on my pendrive, using
rsync -avu
Since then, the version control for my project is grayed-out on every files, I can modify the files and not see the "M" nor the "A" sign. The only files still having version-control working "shared" files for which it works correctly. (Those shared files belong to a different project called "Shared").
I have tried git commit -m, git add . and even git init where the files were. Nothing worked.
Can you please help restoring version control for my project?
UPDATE:
Answers for the questions in commens (and answers):
my git repository is on my local hard drive.
I went to the Organiser-repository pane in XCode and I see my recent git commit -m "sth" as "sth" az a commit. I have a single branch: master.
Im not sure what command would be good to test git, as my commits work (theoretically).
I have a folder named .git in the project folder.
git log is working, showing the same as XCode Organiser-repository pane.
I think the XCode just can't synchronise with the git for some reason, and I don't know how to correct that.
First off, this is not an answer that will fix your problem, I just try to provide some help that might get you closer to a diagnosis.
Git stores its files in a folder named .git. Check if this folder is present in your project. If it's not then your Git repository is gone.
Next, try some basic command such as git log. For this to work, you must first cd to your project folder (or a subfolder thereof), because whenever you run a Git command it will look for the .git folder in the cwd or a parent folder. If git log does not work then your Git repository is broken in some way. Someone else will have to step in to further diagnose the problem, as I am no expert on this subject.
Finally, you should also check whether your rsync command has really sync'ed your project's .git folder with the backup's .git folder. Use this command:
diff -rq /path/to/project/.git /path/to/backup/.git
If there is no difference (as I would expect if rsync has worked correctly) then the problem with your Git repository is both in your project and in your backup. If there are differences then it might be worthwile to try your next steps on a copy of the backup (it should be fine to make the copy in the Finder).
Good luck.

Resources