Can I version control my .bash_profile?

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?

  • Adding git alias to .bash_profile not working
  • Creating a 'git log' alias with formatting
  • How does one change the language of the command line interface of Git?
  • Git .bash_profile Not Working With the Right-click
  • Windows Git - picking up the pieces
  • Showing git branch in shell prompt?
  • 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!

  • Determine commits on a branch not on another
  • How to re-create deleted remote branch?
  • concurrent git pulls to same local repository
  • Is it possible to have git automate resolution of a certain kinds of merge conflicts
  • exclude a subfolder that can appear multiple times
  • git mess -overwrite master with branch?
  • One Solution collect form web for “Can I version control my .bash_profile?”

    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
    
    Git Baby is a git and github fan, let's start git clone.