[Github] Team Project Tips, Solution when Gitignore is not Working
Problem
Since I was using Github in cooperation for the first time, there were a few problems I have encountered with pull and merges.
Before I pushed my working branch to Github, I should have checked whether an existing pull request exists, and if that were the case, the existing pull request should have be reviewed and merged first before I pushed my branch. This would have prevented me from facing merge conflicts after pushing to github. If no files overlapped between the existing pull request and my working branch, there would be no problem, but in any other case, the better practice seems to be to merge the current pull request first.
Best Practice If pull request already exists in GitHub Repo
- Before pushing my commit, check for pull request, merge if possible
- Pull remote master branch to local master branch
- Pull remote master branch to local working branch
- Solve any conflict that occurs (+ add, commit)
- When all conflicts are solved, push my working branch
- Create Pull request
When .gitignore
is not Set Correctly
When first pushing to github from local repository without setting the correct gitignore, not only will the files that shouldn’t be uploaded uploaded, adding these files to gitignore in the future does not remove these from tracked files. This is because git already tracks these files and ignores the gitignore’s request to leave them out. The command to to check the files currently being tracked is as follows.
git ls-tree -r master --name-only
Solution
Following commands remove files that are in gitignore from the list of tracked files.
- Commit all changes
git rm -r --cached .
(removes all files from the tracked files)git add .
⇒git commit -m ".gitignore fix"
(add and commit all files except those in gitignore)
Reference
Untrack files already added to git repository based on .gitignore