How do I merge a old changes into a Git repo? - github

I know this is a common question, but I can't find the answer I'm looking for.
I have a GitHub repository that receive a few bug fixes that I merged into master.
But I have 100s of change in a local folder, and I want to merge the changes with the master.
What I am confused about is where do I start:
Do I create a branch, then drop my new files into that branch folder on my hard drive, commit the changes to this branch, then merge the branches?

If you are the owner of the GitHub repository and have its latest master already cloned, you could simply:
copy over those changes in your local cloned repository folder
git add/commit and push (no merge needed, since you are the owner)
Not that there is no "branch folder": the folder would be the same as your local cloned repository folder.
You can, if you want, make a branch for those changes, in order at least to add/commit those 100s of changes in smaller commits, helping to build a coherent history (instead of one commit, with as commmit message "giant dump of change").
But that would be in the same folder as your currently cloned repository.

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

Adding different projects in a solution to their own git branches

6 projects in a solution all live on master. Im using mvvm with a repository
I would like to have a Data Model branch, a view model branch, a repository branch, etc.
I have created the repo on git hub, created a branch that was not master and added the project on the requisite branch. When I am done, projects all are still on master, other branches exist but are empty showing only the blank solution I started with
In your local clone, you need to:
create your new branch from your current master (which has all the files)
git rm all the files which are not part of what you want to keep in that branch
commit and push (git push -u origin newBranch)
Repeat (get back to master, which still has all the files) for each new branch.
Finally, go back one last time to master, git rm the files you don't need anymore (because they have been referenced by your new branches), add, commit and push.

Git why newly checked remote branch has changed files?

I am new to Git. I have checked new remote branch at my local. As I am checking out a new fresh branch from remote, I don't expect any local changes in the files of my repository.
But somehow few files show changes. I am using Git on Eclipse IDE.
Why is so? Have I misunderstood the concept of new fresh branch checkout?
Update
Based on comments by Tim Biegeleisen and Sajib Khan my understanding was wrong as it is expected behaviour when you check-out remote as a local branch any previous uncommitted changes in the working directory ( Repository ) will carry to the newly checked-out local branch.
Just to put in simple words let me explain with example
Think that your working in master branch and add some new file (Eg file1.txt and file2.txt). Now you don't stage or commit these 2 files then it will be shown as untracked files.
Master Branch
Untracked files
file1.txt
file2.txt
At this particular point of time you switch to another branch then the files which were untracked will be shown in the newly checkout branch.
To over come this problem you can go for the following 2 ways
Stash the files from master branch and then switch to another branch, now it wont show the untracked files of master in newly switched branches. Stashing is nothing but saving the files and then reusing those at later point of time.
commit amending

Committing changes to branch I got by downloading zip from 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

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.