mirror of
https://gitlab.com/ric_harvey/git-guide.git
synced 2024-11-23 12:24:02 +00:00
update footers, spellings and cheat sheet completed
This commit is contained in:
parent
805bb3454e
commit
55c656db4c
6 changed files with 80 additions and 61 deletions
|
@ -9,7 +9,7 @@ Have a read about [what is git](#so-what-is-git) first, this will help you under
|
||||||
- [Sharing code](./commit.md)
|
- [Sharing code](./commit.md)
|
||||||
- [Learning to branch](./branches.md)
|
- [Learning to branch](./branches.md)
|
||||||
- [Merging branches](./merging.md)
|
- [Merging branches](./merging.md)
|
||||||
|
- [Cheat Sheet](./cheat-sheet.md) (Useful commands)
|
||||||
|
|
||||||
## So what is Git?
|
## So what is Git?
|
||||||
|
|
||||||
|
@ -427,4 +427,4 @@ Now you're all ready to get started with learning how to use Git and we can star
|
||||||
[<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/)
|
[<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>
|
<div align=center>
|
||||||
<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://gitlab.com/ric_harvey/git-guide">Git Guide</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://awscommunity.social/@Ric">Ric Harvey</a> is licensed under <a href="https://creativecommons.org/licenses/by-nc/4.0/?ref=chooser-v1" target="_blank" rel="license noopener noreferrer" style="display:inline-block;">CC BY-NC 4.0<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1" alt=""><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1" alt=""><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/nc.svg?ref=chooser-v1" alt=""></a></p>
|
[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")
|
|
@ -143,4 +143,4 @@ Now if you check back in the web gui you'll see only the main branch exists.
|
||||||
[<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/)
|
[<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>
|
<div align=center>
|
||||||
<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://gitlab.com/ric_harvey/git-guide">Git Guide</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://awscommunity.social/@Ric">Ric Harvey</a> is licensed under <a href="https://creativecommons.org/licenses/by-nc/4.0/?ref=chooser-v1" target="_blank" rel="license noopener noreferrer" style="display:inline-block;">CC BY-NC 4.0<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1" alt=""><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1" alt=""><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/nc.svg?ref=chooser-v1" alt=""></a></p>
|
[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")
|
117
cheat-sheet.md
117
cheat-sheet.md
|
@ -1,56 +1,75 @@
|
||||||
## Git Cheatsheet
|
## 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
|
||||||
|
|
||||||
```
|
```
|
||||||
# Clone a Repository
|
git stash
|
||||||
git clone <repository_url>
|
|
||||||
|
|
||||||
# Stage Changes for Commit
|
|
||||||
git add <file(s)>
|
|
||||||
|
|
||||||
# Commit Changes
|
|
||||||
git commit -m "Commit message"
|
|
||||||
|
|
||||||
# Push Changes to the Remote Repository
|
|
||||||
git push
|
|
||||||
|
|
||||||
# Force Push Changes (use with caution)
|
|
||||||
git push --force
|
|
||||||
|
|
||||||
# Reset Working Directory to Last Commit
|
|
||||||
git reset --hard
|
|
||||||
|
|
||||||
# Create a New Branch
|
|
||||||
git branch <branch_name>
|
|
||||||
|
|
||||||
# Switch to a Different Branch
|
|
||||||
git checkout <branch_name>
|
|
||||||
|
|
||||||
# Merge Changes from Another Branch
|
|
||||||
git merge <branch_name>
|
|
||||||
|
|
||||||
# Rebase Changes onto Another Branch (use with caution)
|
|
||||||
git rebase <base_branch>
|
|
||||||
|
|
||||||
# View Status of Working Directory
|
|
||||||
git status
|
|
||||||
|
|
||||||
# View Commit History
|
|
||||||
git log
|
|
||||||
|
|
||||||
# Undo Last Commit (use with caution)
|
|
||||||
git reset --soft HEAD^
|
|
||||||
|
|
||||||
# Discard Changes in Working Directory
|
|
||||||
git restore <file(s)>
|
|
||||||
|
|
||||||
# Retrieve Lost Commit References
|
|
||||||
git reflog
|
|
||||||
|
|
||||||
# Interactive Rebase to Rearrange Commits
|
|
||||||
git rebase --interactive HEAD~3
|
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
##### Follow me for more guides
|
##### Follow me for more guides
|
||||||
|
|
||||||
[<img src="./img/mastodon.png" width="4%">](https://awscommunity.social/@Ric) [<img src="./img/linkedin.png" width="4%">](https://www.linkedin.com/in/richarvey/)
|
[<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")
|
|
@ -155,4 +155,4 @@ git tag -l "v1.*"
|
||||||
[<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/)
|
[<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>
|
<div align=center>
|
||||||
<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://gitlab.com/ric_harvey/git-guide">Git Guide</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://awscommunity.social/@Ric">Ric Harvey</a> is licensed under <a href="https://creativecommons.org/licenses/by-nc/4.0/?ref=chooser-v1" target="_blank" rel="license noopener noreferrer" style="display:inline-block;">CC BY-NC 4.0<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1" alt=""><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1" alt=""><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/nc.svg?ref=chooser-v1" alt=""></a></p>
|
[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")
|
|
@ -104,4 +104,4 @@ Now you can change directory into that new folder and start working.
|
||||||
[<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/)
|
[<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>
|
<div align=center>
|
||||||
<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://gitlab.com/ric_harvey/git-guide">Git Guide</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://awscommunity.social/@Ric">Ric Harvey</a> is licensed under <a href="https://creativecommons.org/licenses/by-nc/4.0/?ref=chooser-v1" target="_blank" rel="license noopener noreferrer" style="display:inline-block;">CC BY-NC 4.0<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1" alt=""><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1" alt=""><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/nc.svg?ref=chooser-v1" alt=""></a></p>
|
[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")
|
14
merging.md
14
merging.md
|
@ -1,13 +1,13 @@
|
||||||
# Bringing code back together
|
# Bringing code back together
|
||||||
|
|
||||||
Merging is a way of getting code from one branch to another, thats to say taking the changes from say the develop branch and bringing those into the main branch for example. You can do merge requests (pull requests on Github) either via the CLI or in the web gui. Lets take a look at the web gui first.
|
Merging is a way of getting code from one branch to another, that's to say taking the changes from say the develop branch and bringing those into the main branch for example. You can do merge requests (pull requests on Github) either via the CLI or in the web GUI. Lets take a look at the web GUI first.
|
||||||
|
|
||||||
## Merge Requests in Gitlab
|
## Merge Requests in Gitlab
|
||||||
We'll use our example of having a branch called **issue 99**. The first thing we need to do is push some code changes to that branch. This effectively moves the HEAD of the branch (issuse 99) forward from the point it was first split. Git now knows theres changes and it's ahead. You'll get a message like this in Gitlab when you commit the code and view the branch:
|
We'll use our example of having a branch called **issue 99**. The first thing we need to do is push some code changes to that branch. This effectively moves the HEAD of the branch (issue99) forward from the point it was first split. Git now knows there's changes and it's ahead. You'll get a message like this in Gitlab when you commit the code and view the branch:
|
||||||
|
|
||||||
![Message in Gitlab after pushing code to a branch](./img/create-merge.png)
|
![Message in Gitlab after pushing code to a branch](./img/create-merge.png)
|
||||||
|
|
||||||
Go ahead and click create merge request. You'll now see a commit message that shows you whats changing and it'll use data from the commit message to populate the merge request.
|
Go ahead and click create merge request. You'll now see a commit message that shows you what's changing and it'll use data from the commit message to populate the merge request.
|
||||||
|
|
||||||
![Merge request ready to go](./img/ready-merge.png)
|
![Merge request ready to go](./img/ready-merge.png)
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ Now if you have merge conflicts instead of it saying **Ready to Merge** you'll h
|
||||||
|
|
||||||
Now hit the blue merge button and you'll get the notification:
|
Now hit the blue merge button and you'll get the notification:
|
||||||
|
|
||||||
![Merge COmpleted](./img/merged.png)
|
![Merge Completed](./img/merged.png)
|
||||||
|
|
||||||
You're all done, the code is merged and if you opted to delete the source branch you'll now be back to having just the one branch in your repository which is called main.
|
You're all done, the code is merged and if you opted to delete the source branch you'll now be back to having just the one branch in your repository which is called main.
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ In order to do this you need to get the commit hash, which in Gitlab can be foun
|
||||||
|
|
||||||
![Commit hash](./img/commit-hash.png)
|
![Commit hash](./img/commit-hash.png)
|
||||||
|
|
||||||
When you identify the commit witht he changes you want run the following commands:
|
When you identify the commit with the changes you want run the following commands:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
git checkout target_branch
|
git checkout target_branch
|
||||||
|
@ -91,7 +91,7 @@ git cherry-pick <commit-hash>
|
||||||
git push origin target_branch
|
git push origin target_branch
|
||||||
```
|
```
|
||||||
|
|
||||||
Now those changes will be selectively merged into your current working directory. Here we can see that the changes from develop have been merged back into the main branch, and the developer working on the release branch doesn't want to pull fromt he HEAD of main or develop for changes, instead they **cherry-pick** the point in time where the develop branch was merged back into main. Heres a visulalisation of that:
|
Now those changes will be selectively merged into your current working directory. Here we can see that the changes from develop have been merged back into the main branch, and the developer working on the release branch doesn't want to pull from the HEAD of main or develop for changes, instead they **cherry-pick** the point in time where the develop branch was merged back into main. Here's a visualisation of that:
|
||||||
|
|
||||||
```mermaid
|
```mermaid
|
||||||
gitGraph
|
gitGraph
|
||||||
|
@ -124,4 +124,4 @@ Now those changes will be selectively merged into your current working directory
|
||||||
[<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/)
|
[<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>
|
<div align=center>
|
||||||
<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://gitlab.com/ric_harvey/git-guide">Git Guide</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://awscommunity.social/@Ric">Ric Harvey</a> is licensed under <a href="https://creativecommons.org/licenses/by-nc/4.0/?ref=chooser-v1" target="_blank" rel="license noopener noreferrer" style="display:inline-block;">CC BY-NC 4.0<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1" alt=""><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1" alt=""><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/nc.svg?ref=chooser-v1" alt=""></a></p>
|
[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")
|
Loading…
Reference in a new issue