How to avoid committing .gitignore file in Eclipse Egit - eclipse

I have a file on my local branch that I have added to the .gitignore file that is shipped with Ecipse git(Egit) but each time I try to commit and push that branch to the remote branch, I see my .gitignore showing as one of the files that has been changed as well as the file I added to the .gitignore file. How can I untrack these two so that only files I really want to commit and push to the central repo are visible when I go to the team->commit in eclipse?

It sounds like you should add .gitignore to your .gitignore file, then git add .gitignore and git commit to commit it. I know you didn't want to touch other files, but this is the best way to go about things. You can always make another branch later and cherry-pick the commits that you want to push into it (without the one that touched .gitignore) before you push to the remote repository.

There are certain things you need to understand first:
1. A file once committed in the repository cannot be marked as untracked unless its deleted from the repository and the deletion is committed. (Not advised in your case)
2. When you add something to .gitignore since its already in source control it "will" show as modified. The other file that you have is also committed in the repository hence it shows it also as modified.
What can you do?
If you are sure that the file you want to ignore should not be part of version control then delete it, commit and push the deletion.
Then you can ignore the file in two ways:
3. Use .gitignore: Add that file in .gitignore and commit and push it so that others also don't face this problem
4. Add the file name in your local .git/info.exclude file
Hope it helps!

Related

Why do I have to call "git add filename" on an edited file previously added

Very simple case where there is only main, no branches ever (it's my personal website). I edited a couple of files and then tried calling "git commit -m "my changes"" - and it would not commit.
I finally tried first calling "git add filename" and it "added" them. The called "git commit" and it committed them. Then push and all is good.
So clearly I don't understand what add means. What does it mean? Why do I need to again add a file already in my Git repository?
Update:
So I think, based on the comments and answers below (please correct if wrong) that:
add adds the present content of files to the list of changes that are to be committed. As it's the present content added, subsequent changes to the file are not added to the list.
commit commits or saves the changed added files to my local repository
push pushes the local repository changes to the git server
git add doesn't refer to file - it refers to the set of changes made on them. In fact, git doesn't really manage files, it manages changes. Once you made a change (and for this purpose, it doesn't matter if it's on a file you've previously committed on or a new file), you need to add (=stage) this change to be committed.

Github - Untracked Files

I'm trying to commit my project using git commit -m "First.". But throw this error, remembering that I wrote git init.
Other version control systems simply commit whatever files have been changed. Git is different. You must first build the commit by adding them to the staging area with git add. Then you git commit what has been added. This allows you to do some very powerful things, like split big changes into multiple commits.
For the above, add everything with git add . then you can commit. Though you probably want to add .vscode, tmp/, *.lock and any other temporary files and directories to your .gitignore file.
For more, please read Git Basics - Recording Changes to the Repository.

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.

How do I undo a commit, and how to push only specific files?

I'm trying to push only a specific file into one of my repos, but I ended pushing all the files in the directory the file is in into my repo. For some reason, I am unable to click on some of these junk files in my github, so I cannot just click on all the useless files in question and just hit delete manually.
How do I undo my faulty push, and how do I only push that 1 specific file to my github in the future?
EDIT: ended up just deleting all the irrelevant files in my folder and committed that.
ended up just deleting all the irrelevant files in my folder and committed that.
That is the safest option, creating a new commit.
But if those irrelevant files were sensitive (should not have been pushed), then you could have:
git reset #~
git add -- only_the_relevant_files
git commit -m "right commit this time"
git push --force
The --force would have cause the previous commit pushed to GitHub to be replaced by the new one.
That can be an issue if others are using your repo. If not, that is a good way to redo that faulty commit.

Configuration - Committing/pushing a single directory to github

I have a working repository setup at github.com
I want to push an entire directory to the server (not the sub-directories). How can I do this with out selecting each file individually?
I am working with in a single folder...when I am complete I'm not sure which files I've modified...the directory is relatively small so I just want to simply commit and push everything in the quickest way possible.
How do I do this?
How do I commit and push all files in a directory?
git commit -am "Commit message" will add all the files that have changed to the index, and then commit them. It won't do anything with files that are not currently being tracked.
Follow it up with git push <githubRepo> and it will push all those changes.
the fast way is to make an alias for:
git add -A && git commit
The -A will add any modifications including new files added. The -a on commit will NOT include new files.