After installing Git, configure name and email address, ** in this order ** :
$ git config --global user.name "name surname"
$ git config --global user.email "e-mail"
From now on, my «commit» will indicate by whom (and his email) they were made.
Place in the project folder and then do $ git init
This will create a hidden folder (.git) with everything GIT needs to manage the project.
$ git clone <repository URL> ← Download a complete project and its version history
$ git remote add <my branch> git@github.com:<user>/<name of the projet>.git ← here, we add a connection to the depot
$ git add page.html style.css | here, 2 files at once |
$ git commit -m "My comment" | Saves a snapshot of file(s) permanently in the version history |
$ git status | List all new files as well as those that have been modified to "commit" |
$ git diff | Shows all the changes since the last "git add" |
$ git diff <file> | Displays the changes of 1 particular file since the last "git add" |
$ git reset <file> | Removes the file from the index, but keeps its contents ! |
$ git show | View metadata and content changes included during the last "commit" |
$ git remote | List the remote servers that you have registered |
$ git remote -v | Displays the URL that Git has stored for each short name |
$ git remote show <remote name> | Show info about a remote repository |
$ git ls-remote | List the fingerprints of all branches |
$ git rm <file> | Deletes the file from the working directory & updates the index |
$ git rm --cached <file> | Deletes the file from the version tracking system but preserves it locally |
$ git mv | Renames the file and prepares the change for a "commit" |
$ git reset <file>
$ git reset HEAD | Cancel the last "commit | $ git reset HEADˆ | cancels the penultimate "commit" | $ git reset d6d98923868578a7f38dea79833b56d0326fcba1 | Undo a commit whose footprint is "d6 ..." | $ git reset d6d98923 | short version of the previous command |
$ git checkout <nom de la branche>
$ git checkout <empreinte du commit>
Show the last x commits : $ git log -n x
$ git reset <commit> ← Cancel all commits after <commit> with the changes
$ git reset --hard <commit> ← Removes all history and changes made after the specified <commit>
→ With 2 lines : create and switch on the new branch
$ git branch <name_new_branch>
$ git checkout <name_new_branch>
→ With 1 line only : create and switch
$ git checkout -b <name_new_branch>
← If the branch is local and is not created on the remote repository
$ git branch -d <name_local_branch>
→ If the branch is present on the romote repository
$ git push origin --delete <name_remote_branch>
$ git branch ← local
$ git branch -a ← local + remote
$ git diff <first_branch> ... <second_branch> ← Show differences in content between 2 branches
$ git diff show <commit> ← Show changes to the metadata and content included in the specified commit
$ git merge <name_branch> ← Combines / merges the history of the specified branch into the current branch
**To do the following, you must have created a new repository on github and set up his account with his SSH key !!**
$ git fetch <name_of_repository> | Get all the history of the named repository |
$ git merge <name_of_repository/<branch> | Merges the repository branch into the current local branch |
$ git push <alias <branch> | Send all commits from the local branch to GitHub |
$ git pull | Retrieves all the repository history and incorporates changes |
$ git push -u origin <branch> | Here, we update the "remote" by pushing the branch <branch> |
Make sure you are registered before;) and send commits to remote repository : $ git push -u origin <name_branch>
Update the local repository : $ git pull ← We recover only the details of the modifications !