Eric Kim
Eric Kim

Reputation: 2698

git - preserve a specific file in repo when pushing

I want to preserve a file in repo when pushing.

Local directory

Dir
----file_1.css
----file_2.css
----file_3.css
----.gitignore

Github repo

repo
----file_1.css
----file_2.css
----file_3.css
----preserve.css
----.gitignore

My local directory does not have preserve.css file. So when I commit and push, preserve.css file is deleted in my repo. However, I want to keep preserve.css in my repo even if it's not present in my local directory.

For personal reason, I want it to be present only in my github repo, and want to edit & save it online only in repo. But making changes in the local directory and pushing prevents me from doing so.

I tried adding preserve.css in .gitignore file in local directory, but it didn't work.

How can I do this?

Upvotes: 2

Views: 115

Answers (1)

lzervos
lzervos

Reputation: 71

Suppose the local repo is a clone of the remote one, Git compares the contents of your local and remote repo to decide what changes have been done. You can see those changes with git status.

In order not to 'commit' the deletion of the file you have to unstage it with git reset HEAD preserve.css or not stage the file at all.

1. git add . 
2. git reset HEAD preserve.css
3. git commit -m "The message you want"
4. git push remote_name branch

Upvotes: 3

Related Questions