Nice to know Git tidbits

1. Add a remote server

After committing your changes locally, how do you push the code to a remote repository. For the sake of this tutorial, we will use a new clean repo on the server. We assume you have SSH access to the server. Create a project directory and initialize it:

mkdir myproject.git
git init --bare myproject.git

Now from the local machine, set the remote repository:

git remote add origin ssh://user@remotemachine:/home/user/repos/myproject.git

If you need to use the project on a system with no access to the remote repository, you can just copy the code to that system. rsync the code there. You could also use tar and scp the project there.:

rsync -avz -e "ssh" /home/user/myprojects/myproject.git user@server:/home/user/myprojects/

2. Set user info, name, e-mail

Change the user info, name and e-mail address:

git config --global --edit

Change the last commit:

git commit --amend --reset-author

3. Merge conflict - use the remote changes

This is before you have a conflict, pull in their changes:

git pull -s recursive -X theirs <remoterepo>

For the default repository:

git pull -X theirs

If there is already a merge conflict:

git checkout --theirs <path/to/file>