Git commands I should know, Part 1

Last Modified On: Thu Feb 13 08:32:53 2025
Posted On: Thu Feb 13 08:32:53 2025

Git commands I should know, Part 1

Date created: 11 January 2025

Last Updated: 13 February 2025

Status: In Progress

5 git commands that are good to know

1. Removing a commited file / folder from Git Repo - git rm --cached

There were times when I have accidentally added a file into the index. As such, including the file's path into .gitignore wouldn't work as expected. The file has already been added!

I still want this file in my working directory but not tracked.

If we did: bash git rm <path-to-file-or-dir> It will remove the file from the index AND my working directory. My file will be deleted, which is not what I want.

However, if we do: bash git rm --cached <path-to-file-or-dir> This will ONLY remove the file the index. I still have my file available in my working directory.

--cached option allows us to "unstage and remove paths from the index"

References

stackoverflow - Remove a file from a Git repository without deleting it from the local filesystem

Git Documentation - git rm

2. Pushing large files onto GitHub - git lfs

3. Changing bases - git rebase

4. Getting updates - git fetch

5. Updating settings - git config