GIT configuration
Configure console output
git config --global color.diff auto
git config --global color.status auto
git config --global color.branch autoSet the local user
git config --global user.name "votre_pseudo"
git config --global user.email moi@email.comIn order to change the global config, or to add aliases,, type:
vi ~/.gitconfig
The content should be:
[color]
diff = auto
status = auto
branch = auto
[user]
name = votre_pseudo
email = moi@email.com
[alias]
ci = commit
co = checkout
st = status
br = branch
Managing repositories
Get a shared repository:
git remote add origin git@github.com:juristr/intro.js.git
git remote -v
git push -u origin masterCreate a repository on a server:
mkdir FOLDER
git init --barePenser à modifier le fichier description
Get a private repository:
git clone ssh://mguenebaud@www.guenmat.com/home/git/repositories/FOLDER
Basic commands
Get the current status
git status
Display the history
git log
Display the files waiting to be committed
git diff
Load a branch or the master
git checkout master
git checkout MYBRANCHAdd files, commit then publish to the server:
git add --all
git commit -m "YOUR COMMENT"
git push --all originReinitialise the repository to the head server version
git reset --hard HEAD
git pullReinitialise the repository to a previous version
git reset --hard c8616db
Retrieving modifications
git pull
Retrieving modifications from a branch
git merge origin/BRANCH
Managing branches
List all branches
git branch
Create a branch and use it
git branch MYBRANCH
git checkout MYBRANCHCreate a branch with uncommitted data:
git checkout -b MYBRANCH
Delete a branch
git branch -d branchname
Show merged branches
git branch --merged master
Show unmerged branches
git branch --no-merged
Merge a branch to the master
git checkout master
git merge MYBRANCHDisplay differences between branches
git diff branch_1..branch_2
Remove local changes
git stash
git stash list
git stash clearGitIgnore
To take into account changes made to .gitignore, type:
git rm --cached -r .
Then add your files and commit as usual.
Migrate a SVN repository
mkdir /data/Projets/temp
cd /data/Projets/temp
git svn init http://svn.guenmat.com/trunk/tools/foscam/foscam-mobile/ --no-metadata
git config svn.authorsfile ../authors.txt
git svn fetch
git remote add origin mguenebaud@www.guenmat.com:/home/git/repositories/foscam-mobile
git push origin --all
cd ..
rm -rf /data/Projets/tempInitialise a desktop or web project
git init
echo -e "build/\nbin/\n.gradle/\n" > .gitignore
git status
git add .
git commit -m 'First upload'
git remote add origin mguenebaud@www.guenmat.com:/home/git/repositories/portail
git push -u origin masterInitialise an android project
git init
echo -e "
# Application files
*.apk
*.ap_
# Files for the dex VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
# Local configuration file (sdk path, etc)
*.iml
.gradle/
/build
**/build
/captures
.externalNativeBuild
.DS_Store
/local.properties
/.idea/workspace.xml
/.idea/libraries" > .gitignore
git status
git add .
git commit -m 'First upload'
git remote add origin mguenebaud@www.guenmat.com:/home/git/repositories/weightmanager-mobile
git push -u origin master
Change the last commit message
git commit --amend
Cancel all commits (warnings, all work would be lost)
git reset --hard HEAD^
The possible options are:
• HEAD : last commit ;
• HEAD^ : before last commit ;
• HEAD^^ : before before last commit ;
• HEAD~2 : before before before last commit ;
d6d98923868578a7f38dea79833b56d0326fcba1 : to this commit
• d6d9892 : to this commit (shortcut name).
To roolback on a file not committed
git checkout nomfichier