98 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
			
		
		
	
	
			98 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Markdown
		
	
	
	
	
	
| ## Configuration
 | ||
| 
 | ||
| Set the global config
 | ||
| 
 | ||
| ```shell
 | ||
| git config --global user.name "[name]"
 | ||
| git config --global user.email "[email]"
 | ||
| ```
 | ||
| 
 | ||
| ## Get started
 | ||
| 
 | ||
| Create a git repository
 | ||
| 
 | ||
| ```shell
 | ||
| git init
 | ||
| ```
 | ||
| 
 | ||
| Clone an existing git repository
 | ||
| 
 | ||
| ```shell
 | ||
| git clone [url]
 | ||
| ```
 | ||
| 
 | ||
| ## Commit
 | ||
| 
 | ||
| Commit all tracked changes
 | ||
| 
 | ||
| ```shell
 | ||
| git commit -am "[commit message]"
 | ||
| ```
 | ||
| 
 | ||
| Add new modifications to the last commit
 | ||
| 
 | ||
| ```shell
 | ||
| git commit --amend --no-edit
 | ||
| ```
 | ||
| 
 | ||
| ## Branches
 | ||
| 
 | ||
| Lists all local branches in your repository (use -a for local and remote branches)
 | ||
| 
 | ||
| ```shell
 | ||
| git branch
 | ||
| ```
 | ||
| 
 | ||
| Switch to an existing branch
 | ||
| 
 | ||
| ```shell
 | ||
| git switch [branch name]
 | ||
| ```
 | ||
| 
 | ||
| Create a new branch
 | ||
| 
 | ||
| ```shell
 | ||
| git checkout -b [branch name]
 | ||
| ```
 | ||
| 
 | ||
| ## I’ve made a mistake
 | ||
| 
 | ||
| Change last commit message
 | ||
| 
 | ||
| ```shell
 | ||
| git commit --amend
 | ||
| ```
 | ||
| 
 | ||
| Undo most recent commit and keep changes
 | ||
| 
 | ||
| ```shell
 | ||
| git reset HEAD~1
 | ||
| ```
 | ||
| 
 | ||
| Undo the `N` most recent commit and keep changes
 | ||
| 
 | ||
| ```shell
 | ||
| git reset HEAD~N
 | ||
| ```
 | ||
| 
 | ||
| Undo most recent commit and get rid of changes
 | ||
| 
 | ||
| ```shell
 | ||
| git reset HEAD~1 --hard
 | ||
| ```
 | ||
| 
 | ||
| Reset branch to remote state
 | ||
| 
 | ||
| ```shell
 | ||
| git fetch origin
 | ||
| git reset --hard origin/[branch-name]
 | ||
| ```
 | ||
| 
 | ||
| ## Miscellaneous
 | ||
| 
 | ||
| Renaming the local master branch to main
 | ||
| 
 | ||
| ```shell
 | ||
| git branch -m master main
 | ||
| ```
 |