change branch master in vs code - github

New to using github in VS Code and accidentally did git init on a high level folder when in fact i meant a low level sub folder. I've tried to do everything i can to un-assign this folder as it has over 5000 items in (.js libraries etc!) but can't seem to google the right solution. If i check git status in the terminal window i get
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
FreeCodeCamp/
folder1/
Test web/
Web cheat sheet.html
index.html
my_profile_pic-min.jpg
my_profile_pic.jpg
folder2/
bio/
blog/
nothing added to commit but untracked files present (use "git add" to track)
PS D:\Web Design>
Not really sure how to remove/change the master folder to the freecodecamp sub folder.
All help welcome.
Thanks.

You can simply delete the .git directory in the high level directory to stop git tracking there, and then do git init again in the appropriate sub-directory to initialize that as a git repository.

Related

Why Github doest load all project files to the folder(For MAC users)

Everyone
I wanted to ask , why github doesn't work as it meant to be. When i clone the project it doesn't show all files and all codes inside it.But when i do "git push" it doesn't show any error and loads the whole project.I am using "ssh" in order to load.
When i open the cloning project it shows ViewController in red with full of empty spaces.
What can be a problem? It is first time i have encountered with this problem.
I have used "git push -u origin main" function in the end.
Thank you in advance.
Check first if the project that you are cloning (from GitHub) has a .gitmodules in it.
That would explain why some folders (the ones listed in the .gitmodules file) are still empty after a clone.
Try and clone your repository again (in a new folder) with:
git clone --recurse-submodules git#github.com/<aUser>/<aRepo>
The other option is, in your local repository that you have pushed, you have nested git subrepositories: look for .git/ subfolder anywhere in your local repo folder (beside the very top folder, since it does include the expected local Git structure in .git/)
Such nested repositories would not be added, committed/pushed. Only a reference to their top SHA1 would be recorded, leaving GitHub displaying their folders as empty, gray with a white arrow.
You would need to:
remove the .git/ locally (in those nested subfolder),
git rm --cached afolder (no trailing /: do that for each folder which had a .git)
add everything,
commit and push again.
I have loaded projects with the "git destination" while it must be "git origin" and in the end we must use "git push origin master"

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

unable to push source folders from eclipse to GIT

steps I have followed
created a repository
convert to maven project(configure -> convert to maven project)
added facet nature.
created folder structure (src/main/java, src/main/resources, src/test/java, src/test/resources)
After that right click on the project -> GIT bash terminal
git init
git commit -m "first commit"
git remote add origin URL
git push -u origin master
After doing all this when I do a checkout(clone repository -> import projects) I am unable to see the source folder like src/main/java.
screen shots attached
project created with folder structure
folder structure when I did a checkout
A git checkout is used to change the branch you are currently working on. It's probably not what you are willing to do here, is it?
My guess regarding your issue is that your git commit didn't commit your newly created files because they were not tracked when you committed your changes.
When you perform a git init, it basically inits a new empty repository, which means that your files are not tracked by default. You first need to git add them before committing.
My explanation is a bit confusing but I guess that if you first git add your files and then commit, it should work.
EDIT: You don't seem to be talking about git checkout here, but rather cloning. This gives even more sense to my answer, I pretty much think that your files have never been committed because you never added them to the staging area.

Files appearing in "unstaged files", but can't stage (red blocking icon)

I have files that have no changes, but appear to be stuck in the staging area.
I started a bitbucket repo from an existing project and from the command line did a $ git remote add origin https://myusername#bitbucket.org/username/myrepo.git in my local project folder. Then did and initial commit from the command line as well $ git push -u origin master. I then loaded the project into the eclipse IDE using the IDE command File>Import Project From File System. After doing this, I found that some of the files from my project where in the staging area, but did not have any changes done to them and clicking them in gitkraken also reported that they were unchanged (yet I could not find a way to remove them from the unstaged files area). Trying to stage these files makes the clicking hand icon flash as a red blocking symbol and nothing else happens.
I tried staging and pushing these "ghost changes" manually in the cli, and get this output:
➜ myproject git:(master) git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: .classpath
modified: .project
modified: some-query.sql
no changes added to commit (use "git add" and/or "git commit -a")
➜ myproject git:(master) git add .classpath .project some-query.sql
➜ myproject git:(master) git commit .classpath .project some-query.sql
...
<some git commit text>
...
➜ myproject git:(master) git push -u origin master
Password for 'https://myusername#bitbucket.org':
....
<some git push success text>
....
However, these files still appear in the "unstaged files" area.
If anyone has any idea what is going on here, input would be appreciated. Thanks :)
I believe you just need to commit the files.
git commit -m "adding .classpath, .project, and some-query.sql modifications"
Look up info on the difference between the working directory, the index, and the repo (there is a fourth area, called the stash, as well). When you stage you are just moving files and changes from the working directory into the index. To actually put those changes into your repo, you need to commit them, which will only commit the things in the index, not the changes just in the working directory.
So initially, the changes were just in your working directory. After git add <files>, they were staged in the index, but not committed. After git commit or git commit -m "<message>" then they are moved into a new commit in your local repo. It is only at this point that push will do anything, because push only moves commits (and references) from local to remote repos, it doesn't touch the working directory or index.

Git pull with reference libraries the path keeps changing

I am working on the same project with another person, and we sync our work using Git. Whenever we do a git push / git pull the paths to our external libraries are updated with paths that are valid only for the other person's machine. The paths are defined here:
I have nothing in my .gitignore file. How can I fix this issue?
You have committed some files to your Git repo that are designed to be user-specific, and should not have been committed.
Add a .gitignore file containing at least the following:
.metadata
.classpath
Or better, import one from e.g. gitignore.io.
To remove the files you have already committed to the repo:
git rm --cached -r .metadata
git rm --cached MyProject/.classpath
and commit the changes (including your .gitignore).
The git rm commands will remove the files from the repo, but not from your working directory, so Eclipse can still find them. However, the files will be deleted from the working directory of anyone else who pulls this commit. To work around this, after the other devs have pulled your changes, you can have them do e.g.:
git checkout HEAD^ -- MyProject/.classpath
git checkout HEAD^ -- .metadata
# Unstage the files, if necessary.
git reset HEAD -- MyProject/.classpath
git reset HEAD -- .metadata
After all of this, you should be able to modify those paths per-user, and the changes will not be tracked by Git.
Group the Selenium jars into a User Library that you can reference from the .classpath file, but define differently on each machine. It adds a layer of indirection that you seem to need. http://help.eclipse.org/neon/topic/org.eclipse.jdt.doc.user/reference/preferences/java/buildpath/ref-preferences-user-libraries.htm?cp=1_4_2_0_1_1