Github: how to checkout my own repository - github

I am very new to GitHub.
I have created a GitHub repository and pushed it from my computer.
Now I need to work on it from another computer.
How can I checkout my own repository? Should I fork it as for other people's repositories?
It seems to me a bit silly to fork my own repository, though.

On the project page (http://github.com/you/project) there will be a link on the right at the bottom of project tools list with a path to a .git repo
Open a terminal and type:
git clone [link to repo here]
That will create a local clone of the repo you can work on, then if you follow the instructions on GitHub to add a remote server you can push your changes back.
Syncing files back and forwards is just as easy;
Computer A (Had the original git repo)
Computer B (Has the cloned repo)
Make some changes on Computer A, then run
git push origin master
Go to computer B, then run
git pull origin master
To sync your new changes, make some changes on computer B then push back
git push origin master

You don't need to fork it on the site, you can just clone your repository. There are links on your repository's page for cloning it with the SSH, git, or HTTP protocols. (Since it's your own, you probably want the SSH one.)
Information about how to clone a repository will come up very early in any git tutorial, so I'm not sure it's worth adding much more here - you might want to start with the one in Pro Git, for example:
http://progit.org/book/ch2-1.html#cloning_an_existing_repository

Related

Cloning a repository not locally, but in a server

Let's say I want to clone a Github repo from somebody but not to my local machine, but to my Github so I can work from the Github website and push changes from there. Is this possible? I seem only to be able to "download" locally whenever I want to clone.
Maybe you can fork the repository first. Then edit the forked repo, and then commit the changes on github directly.

best way to export Eclipse project to GitHub

I need to export an Eclipse project to GitHub. I am using Eclipse-Mars with the eGit plugin. I have spent hours reading documentation, tutorials, and posts and see that there are basically two ways
Create an Eclipse project and a local Git repository. Commit to local repository. Create a repository on GitHub. Push the Eclipse project to the repository on GitHub. When I try this, I get the error "rejected non-fast-forward". I have no idea why. I did create a .gitignore on GitHub when I created the repository - is that causing a problem?
Create a repository on GitHub. In Eclipse, clone this repository and then add files. Commit to local repository, then push. This works, but I end up with a weird configuration on GitHub:
reponame/myprojname/src
when I would prefer the more normal
reponame/src
Which method is the correct way to proceed? Why do I get the push error in the first method, and why the strange folder layout in the second?
You first need to pull the github code into you local machine.
=> git remote add origin
=> git pull origin master
will automatically fetch and merge the github repo with your local copy. You may need to resolve some conflicts that could be generated due to 3-way merge.
After all this, you can use -
=> git push -u origin master
For the second Point,
If you want src/ directory directly under reponame/ on github, then you should execute git clone after creating the project in eclipse and git clone should be executed inside the myprojectname/ directory.
When you created the .gitignore file on GitHub, you created a commit in the repository that isn't in your local copy. You'll need to add the GitHub repo as a remote, pull the change, and then push your local changes:
git remote add origin <path to your repository>
git pull origin master
git push -u origin master

Eclipse pull project to develop on another machine

I have a private repository on github.com and I want to pull it down to another development machine so that I can work with it in Eclipse but I am not sure exactly how to do it.
Do I have to create a local repository first or would that be created when the repository is pulled?
If you use git with eclipse, I assume you use eGit.
If you do, you can simply open File -> Import... -> Git -> Projects from Git -> Clone URI and from there everything should be clear to you. If it is not, just ask again and I will elaborate.
It will create a local repository for you if you chose so (later in the dialog you can chose something like import exisiting projects which is what you want if you already pushed your project to github once).
First, let's get eclipse out of the way. It has nothing to do with pulling/pushing to a remote repository.
The primary purpose of creating a remote repository is code collaboration. You can work on your local and then push to it. Others can pull from the remote and see your changes.
The primary way code collaboration is done in github is using the same model. To create a local branch out of a remote repository, you need to clone the repository. Cloning the repository would create a local master branch (the default branch) that will track the changes you make to your local repository. The other branch to note is the origin/master which tracks the changes you make to the remote repo.
When you want to make changes to the remote, you would need to perform three main steps:
Clone the existing repository: git clone https://github.com/johndoe/foo.git: this will create a local repository with the default master branch. You will work in this branch and when you have made the changes...
Commit the changes: git commit -m "this is the comment to identify my commit later"
Push it to the remote: git push origin master: origin refers to the remote repository; when you have cloned from the remote it is automatically called origin
So basically, you just need to clone the remote repository if you already have the remote on github. You don't need to create it separately.
You can import the project you have cloned into eclipse and work with it accordingly, then commit and push the changes to the remote.
Hope that helps.

How to submit a pull request from a cloned repo?

How to submit a pull request from an existing locally-cloned repo?
Often, I want to look at some libraries source code from github, so I clone it. Later, I discover some issue with the code and raise it on a mailing list, often in passing. The library author says "nice find, can you send a pull request?".
And the answer is "not that easily". I haven't forked the repo yet, Ive cloned it. And there doesn't seem a way I can find to submit a pull request from a cloned repo?
If this limit is true, it feels like the sensible reaction is to fork anything and everything you ever look at, just so that if you ever might want to contribute, you can. And that fills up your github account with many inactive forks.
Doesn't seem a lot of talk about this issue - am I the only person whom this problem affects?
Fork the repo on GitHub, then add your fork repo as a remote to your local cloned copy:
git remote add myfork https://github.com/<myGitHubAccountName>/<repoName>.git
Then you can push to your fork:
git push myfork master
If you're doing more than just this one pull request, you can remove the origin remote and name your fork as origin:
git remote rm origin
git remote add origin https://github.com/<myGitHubAccountName>/<repoName>.git
This is typically what I do. Sometimes I add the original origin as upstream so I still have a reference to it.
If you're ok with installing another binary in your path, github has released a nice little tool called hub.
If you've cloned someone else's repo:
$ hub fork # This creates a fork and adds your repo as a remote
$ git push YOUR_USER feature # push the changes to your new remote
$ hub pull-request # will open your browser
I always clone instead of fork as well and the following steps work for me:
Create a new branch on your cloned repo and make the new change.
Push the change to your branch as the following:
git push origin insert_your_working_branch_name
Now you should be able to find your working branch in pull request from github master.

Fork from a branch in github

Is there a way to fork from a specific branch on GitHub? … For example, moodle has many branches (1.9, 2.0 … and so on). Can a clone be performed of just branch 1.9 and not the master branch always? Is it possible to clone a specific branch onto my PC?
I don’t know a native way yet, but you can do it following this recipe:
Fork the repository in question (called ‘upstream’) on the GitHub website to your workspace there.
Run the GitHub desktop application and clone the repository onto your PC.
Use the GitHub desktop application to open a shell in the repository. (The git commands are not available from the default PowerShell unless you configure that manually.)
Set the source repository as upstream:
git remote add upstream https://github.com/{user}/{source-repo}.git
Fetch the full upstream repository. (Right now, you only have a copy of its master branch.)
git fetch upstream
Make your file system copy the branch you want and give it any name:
git checkout upstream/{branch-in-question}
git checkout -b temporary
Publish your repo using the GitHub desktop application.
On the GitHub website, open your repository and click ‘settings’.
Change the “Default branch” to ‘temporary’. (Just change the drop-down menu, you don’t need to click the “Rename” button.)
Go back to your repository, go to the ‘branches’ tab, now you can delete the “master” branch.
Delete the master branch on your shell and make a new master branch:
git branch -d master
git branch master
git checkout master
git -d temporary
Once more, publish your repo using the GitHub desktop application.
On the GitHub website, open your repository and click ‘settings’.
Change the “Default branch” back to the (new) ‘master’ branch.
Go back to your repository, go to the ‘branches’ tab, now you can delete the “temporary” branch.
This should be what you were looking for. Perhaps GitHub will provide a more convenient way to do this in future (e.g., clicking “Fork” from a project’s branch results in exactly this behaviour).
Cloning means that you create a copy of the whole repository in your account including all branches and tags. However you are free to switch and track branches however you like.
No command line needed. Just create a new branch in your forked repository in GitHub. GitHub will ask you if you want to clone/mirror this new branch from the upstream repository. You can give any name to the new branch.
Yes, you can clone the single branch. For example, you have a branch named release1.0. If you would like to clone this branch into your pc then use the following line of code:
$ git clone git#bitbucket.org:git_username/git_repository_example -b release1.0 --single-branch
For those who don't like working with command-line. Here is a simple guide using the desktop client for GitHub:
Click the fork button of the repo on GitHub.com:
Make sure you have the desktop client installed
Click this button:
Clone the repo
In the desktop client, select the desired branch
Select the branch you'd like to work on and you're done
I'm posting here the method I've used.
Like the OP I wanted to only copy/fork one branch. But couldn't find an easy way.
in your repo create a new branch. It doesn't need to have the same name as the branch you want to fork
once created, verify that it is the selected branch, and click "Compare"
reverse the order of comparison (I have a userscript for that, see my profile if it's something you want to test).
the "base" repository must be yours, with the branch you've created
the "head" repository is the original, and the branch is the branch you want to fork
hit "create pull request" and continue until the PR is applied
That's it. You have the branch forked.
I'm using bitbucket but I'm sure this would work for GitHub as well.
Create a new repository
Checkout the branch using GitExtensions
Click Push to open the Push dialog
Set the destination URL to the new repository
Set the destination branch to "master"
Push
Your new repository will have the full history of the one branch only (not all branches like forking will have).
A fast, alternative approach is to create your own new repo.
Go to https://github.com/new and make a new repo. Do not initialize with README.
Scroll down to get your git remote
Then:
git remote rm origin
git config master.remote origin
git config master.merge refs/heads/master
// Run code from above image
git push --set-upstream origin yourbranchname
You will have a new repo with the original repo's code and a branch that can be made into a pull request.
SOLUTION:
For remote repository on GitHub and local repository
After fork all branches to your GitHub repository, you can delete Redundant branches in your GitHub repository.
And then you can only clone the branches you need to local.
Step One
Step Two
Only For local repository
git clone -b <branch name> --single-branch <repository>
If you want to further save your disk space, you can clone remote repository without history:
git clone -b <branch name> --depth 1 <repository>
notice: --depth implies --single-branch unless --no-single-branch is given.
https://git-scm.com/docs/git-clone
Switch to the branch you need in source repo
Click "Fork". You'll get forked master and the branch you're in.
I don't know how it works with more branches, but for my needs worked pretty well.