Committing changes to branch I got by downloading zip from GitHub - github

I'm working on a repository that has two branches: Master, and Release1.
The branch I need is Release1. I went to the site and tried to clone it, but no matter what I did I got the Master branch cloned.
So I gave up and downloaded the branche's zip to my file system. I added it to Eclipse and worked on it.
Now I need to commit my changes. But neither the branch nor the repository show up in my visual tool.
When I try to add a local repository the visual tool tells me the folder is not a repository.
Is there a solution? I have quite a few changes on my local project and I have to commit them.

The Zip download is not a Git repository, it's only a collection of the files at that moment in time. Here's a way you might be able to get your changes into the repository:
Clone the repository properly
Copy your current files into the cloned directory
git status and git diff to check that the changes are what you expect
git commit
When you cloned the repository the first time, you were getting both branches - a Git clone is a fully copy of everything: every branch, all history, etc. The default branch is typically master. After you clone, if you want to switch to the other branch, use git checkout Release1.

What GUI are you using? When trying to clone you have to make sure you change the branch you are cloning from (usually in a drop down menu or you may have to type it in). If you can successfully clone from Master, than you should be able to change to or "checkout" Release1 branch.
Just downloading the zip, just gets you the source code and doesn't have any connection to git. To save and push your changes you will need to clone the repository and checkout Release1

Related

Make the current commit the only (initial) commit in a Git repository that was created with GitHub Desktop

I created my first GitHub repository using GitHub Desktop (Windows). It is a real mess with many revisions that are quite meaningless and some versions of files that I would rather were never uploaded. This was the result of a lot of experimenting to get the feel for how things would appear on GitHub. I want to get rid of all the history versions.
I am tempted to just copy my files on my drive to another folder then delete the repository folder from my drive. Also delete it from GitHub.
Then create a new repository with GitHub Desktop, perhaps with the same name or with a different name then rename it to the original. Could it be a simple as that or will GitHub still retain the files somewhere?
I haven't tried this because in my searching I keep finding all the complex steps to be performed to remove histories or remove files.
I sort of feel that what I am proposing is too simple.
Any opinions?
All of this got too confusing.
I just did what I said in the start of the thread.
It seems GitHub Desktop has some Username/Password problem and won't let me "Publish branch".
So I went to GitHub and created a new repository and uploaded all the files from my local folder.
It looks good to me.
There may be problems in the future. I guess I'll cross that bridge when (if) I come to it.
An alternative approach is to switch to command line and:
delete the .git folder in your repository
recreate it (git init .)
reset the origin remote: git remote add origin https://github.com//
Make a first commit with your current content:
git add .
git commit -m "first commit"
overwrite everything on the remote repo
git push --force -u origin master
The end result will be the same repo but with only one commit.
You can then switch back to GitHub Desktop.
From here.
First make sure you have Git for Windows installed, you are going to need to do git commands manually sooner or later.
Go to your local repository on your computer where your project is located. It's a good idea to show hidden files so you can see that you have the .git-folder and that the .gitignore-file is in place.
Go to the folder where the .git-folder is, right-click and click git bash here.
Now enter these commands:
Create Orphan Branch – Create a new orphan branch in git repository. The newly created branch will not show in ‘git branch’ command.
git checkout --orphan temp_branch
Add Files to Branch – Now add all files to newly created branch and commit them using following commands. Don't forget .gitignore!
git add .
git commit -m "the first commit"
Delete master Branch – Now you can delete the master branch from your git repository.
git branch -D master
Rename Current Branch – After deleting the master branch, let’s rename newly created branch name to master.
git branch -m master
Push Changes – You have completed the changes to your local git repository. Finally, push your changes to the remote (Github) repository forcefully.
git push -f origin master
Git overview

Egit: You are in detached head state. This means that you don't have a local branch checked out

I recently created a project on Eclipse. I set up a git repository on the project. Pushed the code to a new repository on GitLab.
I checked out (Import->Project from Git) the project to another laptop, made updates, committed it as another author and pushed it back to repository (2nd commit /revision). I only removed the target runtimes from the project as the changes.
I went to my 1st laptop and wanted to try update / pull my code. I right-clicked on the repository from the Git Repository view -> Remote -> Fetch. I entered the path to the repository and etc and fetched the repository. But, my project still has the old code having the target runtime. I know I only 'fetched' the repository, not 'pulled' maybe.
So I was confused, the code was not updated. If I am not mistaken, I right-clicked the repository again, clicked on 'Check Out'. This was the result :
After 'Checkin Out', the target runtimes on my project were removed, updated like from the 2nd commit. But there are now 2 branches and 2 refs. I don't what state my local repository is in now. And/but the local master branch was still in 'initial commit', isn't it confusing?.. My code has been updated..
I only read a bit of the git manual online, and I haven't yet be able to wrap my head around concepts like refs.
I could just delete the project and Import->Project from Git, right?
But if I can I would like to know what happened to my project (local repository) and how to fix this?
Thx
I'm not familiar with egit and its menus. But I try to answer your question with git commands which you can run in the console. And I think you can figure out which egit menu items are corresponding to these commands.
You wanted to pull and update the local master in the first laptop repository. You needed git checkout master first, which could be skipped if you were already on master and then git pull origin master. However you did git fetch origin master instead, which just updated origin/master with the new commit. It would have been okay to use git fetch origin master if git merge FETCH_HEAD or git merge origin/master followed imediately, because in many cases pull = fetch + merge, but you didn't.
I guess you then did git checkout origin/master. Checking out origin/master leads to detached HEAD state. To make it easier, you could just consider the detached HEAD as a nameless branch. When you make new commits, this namelss branch will grow. But you can't see these commits on other branches unless you apply these commits to them. Git has some commands to apply commits, including git merge, git rebase, git cherrypick, etc.
To fix the current situation, you can simply run git checkout master;git pull origin master.
So to make my answer more simply. Commit changes on your deateached head and make branch with this commit and then merge it together and push to master.
You can just download again your project if you didn't make changes on detached head that you need.

Update a GitHub repository without cloning

Here's the situation, we are currently working on a project and lately we decided to upload it on GitHub. Now I made my changes and I want to push the changes onto the repository.
As far as I read, in order to make changes you need to clone the repository but that will download all files from the repository and I already have all of the source files.
I'm using GitHub desktop and I can't find any option to clone without downloading and update or create branches from my existing files. Creating a local one is an option but it needs to be uploaded as a separate repository instead of linking it to a current one.
Is there any way to push updates, create branches to the repository from my local project to an existing repository?
Your local project should already be a git repo, if you uploaded it to GitHub.
But in case it is not, switch to command-line, and do inside the root folder of your project (which should shows the same files as your remote repo):
git init .
git remote add origin https://github.com/<user>/<project>
git fetch
The fetch part will download the repo but leave your files alone.
(But do a backup still, just to be safe)
git branch master origin/master
git reset master
From there, your GitHub Desktop should show you any diff between your files and what was fetched from the repo.

Egit push doesn't change files in remote repository

I came to know about the git / egit version control system last week, seems too good to be true .So thought to shift from SVN to git..Since last week I am trying to understand the basics and concepts of git.
So I created a test environment for understanding the workflow of egit in eclipse as following.
I am following the strategy of remote tracking there are two repositories named local and remote used for understanding the workflow.
I created a repository named 'remote' with an emtpy index.php file and has one master branch and imported the project into eclipse.
I created another git repository named 'local' by cloning the above 'remote' git repo, this repository is now tracked by 'remote' repository has one master branch and origin/master remote tracking branch.
I imported the project from 'local' git repo. into my eclipse workbench and changed the index.php file using eclipse php editor -> committed changes to local's master branch and -> performed push from local master branch.
When checking the remote working directory .. there is no change updated which I did in local's index.php file , however master branch in the remote repository view shows the latest commit which I committed in the local's master branch, but unfortunately files are not updated, it just adds asterisk mark to all changed files in my remote project view.
So researching about the asterisk mark I found its in staged condition .So can anyone lead me to the right way explaining how to successfully perform push operation from local's master branch to remote's branch I will be grateful.
this is the picture of my egit test case set up in eclipse for understanding the workflow. you can see the asterisk mark in the remote project after performing push from local repository,you can see all three branches viz.local's master, origin/master and remote's master branches shows same latest commit.
1
Thank You.
I tried using bare repo. as a remote, when I push from changes from local to remote, I don't find any files in remote repo. Just branch gets updated with the latest commit.
That seems normal, since a bare repo has *no working tree, meaning no files.
You would need to clone that remote repo, and add this cloned repo (non-bare) as a project in your Eclipse, in order to:
push from your first Egit-managed repo to the bare remote repo
pull from that same bare repo to your second Egit-managed non-bare repo.

Git completely replaced changes in history. How to restore files?

I have git repository on bitbucket. I use it from Eclipse for a while, but then copy Eclipse project with local git repository to another place on the filesystem and work locally for 3 weeks. I'm a newbie with git, so I just copy the project as is.
Yesterday I try to push local changes and then switch to the remote branch. Now I see in git-gui only old bitbucket commits and no new files. I search in git-gui everywhere. But the size of the repository tells me that my new files are still there (on bitbucket 16mb, locally >300mb).
git branch shows me 2 branches (master and * (no branch)) and both have bitbucket commits. I didn't make any branches, I just first cloned the repo from bitbucket, then made commits, then made some actions trying to push the copied repo and then change branch. Any idea of how can I restore my local files will be greatly appreciated!
I'm really having a hard time understanding what the exact situation is.
However, if you say all the files are still in the local repo, a simple:
git reflog
is all you need to see recent commits on all branches. Find the right commit you want to go back to, and take it from there.