git --version
git config --list
As your regular user...
git config --global user.name "FirstName LastName"
git config --global user.email "EmailAddress"
git config --global branch.autosetuprebase always
NOTE: Avoids merge commits for pullinggit config --global color.ui true
git config --global color.status auto
git config --global color.branch auto
git config --global core.editor vim
git config --global merge.tool vimdiff
As 'root' on the server you want to be the remote git server...
For testing this can be a new user on your local machine but note that unless you have another user on another machine using this git server then you lose the key advantage of the distributed nature of git.groupadd dev
useradd -G devs -d /home/gituser -m -s /bin/bash gituser
passwd gituser
As 'gituser' (in /home/gituser)...
mkdir project.git
cd project.git
git --bare init
As your regular user (assuming you do not already have a public key generated under your ~/.ssh directory...
ssh-keygen
ssh-copy-id -i ~/.ssh/id_rsa.pub gituser@gitserver
As your regular user (usually you would want to be doing this in your home directory)...
mkdir local_repo
cd local_repo
git init
echo 'TODO: Add contents for README' > README
git status -s
git add .
git status -s
git commit -m 'Initial commit'
git log
As your regular user...
This needs to happen only once for each user who intends to use the 'remote' repository...git remote add origin gituser@gitserver:project.git
git push origin master
Clone the Git repository as a working copy.
Modify the working copy by adding/editing files.
If necessary, you also update the working copy by taking other developer's changes.
Review the changes before commit.
Commit changes. If everything is fine, then you push the changes to the repository.
After committing, if you realize something is wrong, then you correct the last commit and push the changes to the repository.
As your regular user...
mkdir local_repo
cd local_repo
git clone gituser@gitserver:project.git
cd project
now, add or change files in this directory
git status -s
git add file
git log
git show commitid
make any changes
git diff
Git diff shows '+' sign before lines, which are newly added and '−' for deleted lines.git status -s
git add file
git status -s
git commit --amend -m 'comment'
git log
git show commitid
git push origin master # Until this point, others cannot see the amendment
When two people make changes to the same file, the second user to try to push will face this situation...
git push origin master # will fail with an error
git pull # to refresh local repository
git push origin master
To pause work and upload it to the repository without committing it...
git status -s
git stash # Stash
git status -s
git stash list
git status -s
git stash pop # Get it back to work on again (Pop)
To move a directory or file...
mkdir src
git mv file.c src/
git status -s
git commit -m "Modified directory structure"
git push origin master
Other users will see the change after the next git pull
git commit -a -m 'Renamed file.c to string.c'
Note use of -a flaggit push origin master
git rm filename
git commit -a -m "Removed filename"
git push origin master
git checkout filename
git checkout HEAD -- filename