質問

In the folder tree:

Hard_Disk:
- Applications
- Users:
- - User-1_folder
- - User-2_folder:
- - - - .bash_history
- - - - .bash_profile
- - - - .bashrc
- - - - .gitconfig
- - - - .gitignore_global
- - - - .ssh
- - - - Applications
- - - - Desktop
- - - - ...
- - User-3_folder
- Library
- System

Can I version control my .bash_profile or any other file in the same folder as .gitconfig?

Is it safe to initiate a git repository in the User_folder?

Ignoring all folders and .gitconfig itself, just to keep some settings on track!

役に立ちましたか?

解決

This is one way to go about it, although not so clean it does the job without the hassle of maintaining symlinks on each machine:

cd ~
git init

# Ignore everything except .bash_profile and .gitignore
echo '/*' > .gitignore
echo '!/.bash_profile' >> .gitignore
echo '!/.gitignore' >> .gitignore

# Only .bash_profile and .gitignore would be added
git add .

# Commit
git commit -m "Adding .bash_profile and .gitignore"

# Add the remote details and push the master branch into the remote
git remote add <REMOTE-NAME> <REMOTE-URL>
git push <REMOTE-NAME> master

One thing you got to be careful is when you're cloning this repo on another machine, git clone will error if the destination directory is not empty. So you could do something like this to initially set it up:

mkdir -p ~/temp-git-dir
cd ~
git clone <REPO-URL> ~/temp-git-dir
mv ~/temp-git-dir/.git .
rm -rf ~/temp-git-dir
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top