References

Pro Git book by Scott Chacon and Ben Straubfor.

Setup a remote repository

Suppose you want to setup git version control in a project directory project.

Make the initial commit

cd project
git init
git add -A
git commit -m "initial commit - adding everything"

Clone the bare git directory

cd ..
git clone --bare ./project project.git

Recursively copy the bare git repository to the server.

scp P <port> -r ./project.git user@server:/opt/git/project.git

Add the repository to your list of remotes using the standard user@server:port format.

cd ./project
git remote add origin ssh://user@server:port/opt/git/project.git
git remote -v

Check the remote

git remote show origin

Reverting changes to HEAD for a single file

To revert changes for a given file to the latest commit (i.e., HEAD):

git checkout filename

If the file you wish to revert happens to be the name of a branch:

git checkout -- filename

Ignoring files in a git repository, i.e. gitignore

See gitignore repo.

Tells you what’s currently being used to ignore stuff:

git config --get core.excludesfile

Configure git to ignore ~/.gitignore

git config --global core.excludesfile '~/.gitignore'