Commands
Initial configuration
Define a name
git config --global user.name "Your name"
Define an email
git config user.email "your@email.com"
This config is necessary for commits.
Start a project
Init a repository in the current folder
git init
Clone an existing repository
git clone https://github.com/user/repo.git
Workflow
View the status of modified files
git status
Add a file to track
git add file.txt
Add all updated files
git add .
Add changes
git commit -m "Description message"
Push to remote repository
git push origin main
Retrieve the updates
git pull
Branches
Show the current branch
git branch
List all branches
git branch -a
Create a new branch
git branch new-branch
Switch branches
git checkout branch-name
Create and Switch on a branch
git checkout -b branch-name
Merge a branch
git merge branch-name
Collaboration
Add a new remote repository
git remote add origin https://github.com/user/repo.git
List remote repositories
git remote -v
Retrieve changes without merging
git fetch
History
View history of commits
git log
See the differences between files
git diff
Cancel a modified file (before commit)
git restore file.txt
Useful commands
Stash (save temporarily)
git stash
Apply a stash
git stash pop
Delete a file from the trace
git rm file.txt
Rename / Move a file
git mv old-name new-name
Create a tag
git tag v1.0.0
Reminder
git help [commande]
Pull Request
Create PR
gh pr create --title "New fonctionnality" --body "Detailed description" --base <branch>
title
: title of the PR.--body
: modifications description.--base
: the vised branch.
You can also use this command, to launch the interactiv assistant without arguments.
gh pr create
List opened PR
gh pr list
Approuve a PR
gh pr review <PR_NUMBER> --approve