2024-05-10 21:25:51 +00:00
## Git Cheat Sheet
2024-05-02 10:46:38 +00:00
2024-05-10 21:25:51 +00:00
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 >
2024-05-02 10:46:38 +00:00
```
2024-05-10 21:25:51 +00:00
#### Stage Changes for Commit
```
# Add a single file
2024-05-02 10:46:38 +00:00
2024-05-10 21:25:51 +00:00
git add < FILE >
2024-05-02 10:46:38 +00:00
2024-05-10 21:25:51 +00:00
# or add all files
2024-05-02 10:46:38 +00:00
2024-05-10 21:25:51 +00:00
git add .
```
2024-05-02 10:46:38 +00:00
2024-05-10 21:25:51 +00:00
#### Commit Changes
```
# See a log and edit message in editor
2024-05-02 10:46:38 +00:00
2024-05-10 21:25:51 +00:00
git commit -a
2024-05-02 10:46:38 +00:00
2024-05-10 21:25:51 +00:00
# Add message on command line
2024-05-02 10:46:38 +00:00
2024-05-10 21:25:51 +00:00
git commit -m "Commit message"
```
#### Push Changes to the Remote Repository
```
git push
```
2024-05-02 10:46:38 +00:00
2024-05-10 21:25:51 +00:00
#### Create a New Branch
```
git branch < BRANCH >
```
2024-05-02 10:46:38 +00:00
2024-05-10 21:25:51 +00:00
#### Switch to a Different Branch
```
git checkout < BRANCH >
```
2024-05-02 10:46:38 +00:00
2024-05-10 21:25:51 +00:00
#### Merge Changes from Another Branch
```
# First check out to the target branch
git merge < BRANCH >
```
2024-05-02 10:46:38 +00:00
2024-05-10 21:25:51 +00:00
### Other useful commands
2024-05-02 10:46:38 +00:00
2024-05-10 21:25:51 +00:00
#### Look at the git log
```
git log
```
2024-05-02 10:46:38 +00:00
2024-05-10 21:25:51 +00:00
#### Stash changes
Removes your changes and takes you back to the original state of the repo
2024-05-02 10:46:38 +00:00
2024-05-10 21:25:51 +00:00
```
git stash
2024-05-02 10:46:38 +00:00
```
---
2024-05-10 21:25:51 +00:00
2024-05-02 10:46:38 +00:00
##### Follow me for more guides
2024-05-10 21:25:51 +00:00
[<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" )