Git why newly checked remote branch has changed files? - eclipse

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

Related

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

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.

github files not the same as latest commit?

I am having trouble understanding/ updating one of my git repos. There is one branch, master. I created the repo on github. Cloned and made edits in Windows, commited, pushed. Cloned in Mac, made edits, committed, and pushed. A few days later made commits from Windows again. Now Github shows my latest commit different code than the files do. Shouldn't github files be synced to the latest commit?
On my Windows machine the repo matches the commit changes shown in the latest commit. (The commit hash link in upper right of github.)
This is different from the repo and on my Mac, which matches the Raw file.
Why does the commit hash show a file with changes, while clicking the file link show the file before the changes? (seems to be root of problem)
How can the files be different than the most current commit?
The repo in question:
The file:
https://github.com/dval/HWiNFO64-Crunch/blob/master/HWiNFO64%20parsing.R
The hash:
https://github.com/dval/HWiNFO64-Crunch/commit/57c44c441ee0d2b39fa5248eaf44b10a3658a023

How to merge local folder and its structure to github?

I am still a beginner and I locally made a folder of my Project and uploaded it as a repository in GitHub using GitHubDesktop. Now I changed the structure of the files (deleted some sub-folders and moved files here and there locally). Now I don't see those changes in my GitHubDesktopas something which I can push to the GitHub online and reflect the changes there.
I am not sure how to achieve that:
(One way I can think is to reclone and download the online GitHub repository to local, move the changed files again and then commit from GitHubDesktop) , but I am not sure if it will work because I did the almost the same thing just without recloning: but after the reorganization, the changes are not appearing in my GitHubDekstop which I can commit.
Any advice would be great. Thank you.
This is my repository (https://github.com/grammilo/Codes) whose organization I want to copy from a local folder which goes by the same name and was previously cloned from it.
When you go to the directory of the repository in your terminal, checkout your master branch
git checkout master
and use
git diff
this will display any changes made to the files and file structure in green and red. You can delete folders and files directly from your file system or from the terminal, whichever you prefer and these changes will display when you use git diff. After your changes are made use
git add
this will stage your changes to be committed. You can use
git status
to make sure your changes are ones you would like to make.
Use
git pull
to pull any changes from your repository and when you are ready to commit your changes simply use
git push origin master
this will commit your changes to the remote repository on GitHub from your command line without using GitHub Desktop. Check out the git documentation for more in depth explanations but that should achieve what you're looking for.

Eclipse Git : auto-synchronising 2 branches

I am working on a project with some mates.
Yesterday I cloned the project with the intention to add a functionality.
I have 2 local branches that are develop (the main branch) and pageContent (my feature branch).
The problem I am currently encountering is when I edit something on my feature branch, it automatically edits it on my developp branch too (I did not commit anything).
I checked out on my developp branch to delete the edition and when I checked out on my feature branch, the edition was deleted too ...
The branches seem to be auto-synchronised.
I checked out on my develop branch to delete the edition and when I checked out on my feature branch, the edition was deleted too ...
This is how git works.
In the following diagram you can see the 3 states.
Git has three main states that your files can reside in.
They are all shared between your branches. but when you checkout branch you change the HEAD so you end up with the staging area && working directory shared between your repository even when you checkout branches.
Since you did not commit (i assume that what happened) when you switch branches you see the changes following you to your new branch.
If you don't want the changes to follow you you need to commit (or stash) your work before switching to the branch.
How to checkout different branch with clean working directory and stage area?
If you wish to checkout clean branch without any "leftovers" in your working directory and staging are you can create a new worktree which will result in shared view of your repository (all the content is shared) but with a different working directory and staging area.
From git v2.5
git worktree add <new_path>
Now do whatever you want in any of your branches. It will create 2 separate working folders separated from each other while pointing to the same repository.
Using wortree you don't have to do any clear or reset in order to remove all your staged and untracked content.
Here is demo of how to do it:

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