mirror of
https://gitlab.com/ric_harvey/git-guide.git
synced 2024-11-27 13:24:03 +00:00
75 lines
No EOL
1.4 KiB
Markdown
75 lines
No EOL
1.4 KiB
Markdown
## Git Cheat Sheet
|
|
|
|
Here are a collection of useful git commands covered in this guide so far:
|
|
|
|
#### Clone a Repository
|
|
```
|
|
# Use SSH if you want to commit back HTTPS is fine for cloning
|
|
git clone <REPOSITORY_URL>
|
|
```
|
|
|
|
#### Stage Changes for Commit
|
|
```
|
|
# Add a single file
|
|
|
|
git add <FILE>
|
|
|
|
# or add all files
|
|
|
|
git add .
|
|
```
|
|
|
|
#### Commit Changes
|
|
```
|
|
# See a log and edit message in editor
|
|
|
|
git commit -a
|
|
|
|
# Add message on command line
|
|
|
|
git commit -m "Commit message"
|
|
```
|
|
|
|
#### Push Changes to the Remote Repository
|
|
```
|
|
git push
|
|
```
|
|
|
|
#### Create a New Branch
|
|
```
|
|
git branch <BRANCH>
|
|
```
|
|
|
|
#### Switch to a Different Branch
|
|
```
|
|
git checkout <BRANCH>
|
|
```
|
|
|
|
#### Merge Changes from Another Branch
|
|
```
|
|
# First check out to the target branch
|
|
git merge <BRANCH>
|
|
```
|
|
|
|
### Other useful commands
|
|
|
|
#### Look at the git log
|
|
```
|
|
git log
|
|
```
|
|
|
|
#### Stash changes
|
|
Removes your changes and takes you back to the original state of the repo
|
|
|
|
```
|
|
git stash
|
|
```
|
|
|
|
---
|
|
|
|
##### Follow me for more guides
|
|
|
|
[<img src="./img/mastodon.png">](https://awscommunity.social/@Ric) [<img src="./img/gitlab.png">](https://gitlab.com/ric_harvey) [<img src="./img/linkedin.png">](https://www.linkedin.com/in/richarvey/)
|
|
|
|
<div align=center>
|
|
[Git Guide](https://gitlab.com/ric_harvey/git-guide) by [Ric Harvey](https://awscommunity.social/@Ric) is licensed under [CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/?ref=chooser-v1") |