Extremely Serious

Category: Git (Page 2 of 2)

Local Working Directory Ignore in Git

Ignoring files in git can be in the well known .gitignore file or in the .git/info/exclude file.

What's the difference between the two files?

File

Description

.gitignore

Operates at the repository level and everyone is sharing this file.

.git/info/exclude

Operates at the local working directory (i.e. normally the root of the cloned repository) level and only you has this file.

Exclude File

If .git/info/exclude file is present it must have the same formatting rule as the .gitignore file.

If the file to be ignored was already in the repository and you can still see it as modified. You can execute the following command:

git update-index --assume-unchanged <FILENAME>

Example:

git update-index --assume-unchanged config/database-config.xml

The reversal of this command is the following:

git update-index --no-assume-unchanged <FILENAME>

 

Resetting GitHub Forked Master with Upstream Master Branch

If your GitHub forked master branch is ahead from the upstream's master branch and you wanted to make it even (i.e. also lose some work). The following procedure might help you.

Note: If you have your default branch protected perform steps 1, 2, 3, 7, 8 and 9.  Otherwise just do steps 4, 5 and 6.

  1. Open a terminal (i.e. powershell, cmd, bash) and checkout the master of the upstream to a temporary branch (i.e. this could be anything) using the following syntax:
    git checkout -b <temporary-branch> upstream/master

    Example

    git checkout -b temp-branch upstream/master

    Where <temporary-branch> is temp-branch.

  2. Push the temporary-branch to your origin using the following syntax:
    git push origin <temporary-branch>

    Example

    git push origin temp-branch

    Using the <temporary-branch> from the example in step 1.

  3. On your browser, access your forked GitHub project and update the default branch to your temporary-branch.
  4. On your terminal (i.e. powershell, cmd, bash), switch to your master branch using the following command:
    git checkout master
  5. Reset the master based on the upstream's master branch using the following command:
    git reset --hard upstream/master
  6. Push the update to your master using the following command:
    git push origin master --force

    Note: If you didn't do step 3 this and the branch is proctected command will fail.

  7. On your browser, access your forked GitHub project and update the default branch to master.
  8. Going back to your terminal, delete the local temporary-branch using the following syntax:
    git branch -D <temporary-branch>

    Example

    git branch -D temp-branch

    Using the <temporary-branch> from the example in step 1.

  9. Delete the remote temporary-branch on your origin using the following syntax:
    git push origin --delete <temporary-branch>

    Example

    git push origin --delete temp-branch

    Using the <temporary-branch> from the example in step 1.

Newer posts »