diff --git a/README.md b/README.md index b17c62a..92ed9fa 100644 --- a/README.md +++ b/README.md @@ -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) - [Learning to branch](./branches.md) - [Merging branches](./merging.md) - +- [Cheat Sheet](./cheat-sheet.md) (Useful commands) ## 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 [](https://awscommunity.social/@Ric) [](https://gitlab.com/ric_harvey) [](https://www.linkedin.com/in/richarvey/)
-

Git Guide by Ric Harvey is licensed under CC BY-NC 4.0

\ No newline at end of file +[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") \ No newline at end of file diff --git a/branches.md b/branches.md index 6874552..9d19b2b 100644 --- a/branches.md +++ b/branches.md @@ -143,4 +143,4 @@ Now if you check back in the web gui you'll see only the main branch exists. [](https://awscommunity.social/@Ric) [](https://gitlab.com/ric_harvey) [](https://www.linkedin.com/in/richarvey/)
-

Git Guide by Ric Harvey is licensed under CC BY-NC 4.0

\ No newline at end of file +[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") \ No newline at end of file diff --git a/cheat-sheet.md b/cheat-sheet.md index 39cbf15..a9a7a8b 100644 --- a/cheat-sheet.md +++ b/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 +``` + +#### Stage Changes for Commit +``` +# Add a single file + +git add + +# 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 +``` + +#### Switch to a Different Branch +``` +git checkout +``` + +#### Merge Changes from Another Branch +``` +# First check out to the target branch +git merge +``` + +### 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 clone - -# Stage Changes for Commit -git add - -# 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 - -# Switch to a Different Branch -git checkout - -# Merge Changes from Another Branch -git merge - -# Rebase Changes onto Another Branch (use with caution) -git rebase - -# 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 - -# Retrieve Lost Commit References -git reflog - -# Interactive Rebase to Rearrange Commits -git rebase --interactive HEAD~3 +git stash ``` --- + ##### Follow me for more guides -[](https://awscommunity.social/@Ric) [](https://www.linkedin.com/in/richarvey/) +[](https://awscommunity.social/@Ric) [](https://gitlab.com/ric_harvey) [](https://www.linkedin.com/in/richarvey/) + +
+[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") \ No newline at end of file diff --git a/commit.md b/commit.md index d30a4a4..90424cc 100644 --- a/commit.md +++ b/commit.md @@ -155,4 +155,4 @@ git tag -l "v1.*" [](https://awscommunity.social/@Ric) [](https://gitlab.com/ric_harvey) [](https://www.linkedin.com/in/richarvey/)
-

Git Guide by Ric Harvey is licensed under CC BY-NC 4.0

\ No newline at end of file +[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") \ No newline at end of file diff --git a/getting-code.md b/getting-code.md index 01b8500..7544eef 100644 --- a/getting-code.md +++ b/getting-code.md @@ -104,4 +104,4 @@ Now you can change directory into that new folder and start working. [](https://awscommunity.social/@Ric) [](https://gitlab.com/ric_harvey) [](https://www.linkedin.com/in/richarvey/)
-

Git Guide by Ric Harvey is licensed under CC BY-NC 4.0

\ No newline at end of file +[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") \ No newline at end of file diff --git a/merging.md b/merging.md index 376801a..f6c3548 100644 --- a/merging.md +++ b/merging.md @@ -1,13 +1,13 @@ # 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 -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) -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) @@ -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: -![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. @@ -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) -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 git checkout target_branch @@ -91,7 +91,7 @@ git cherry-pick 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 gitGraph @@ -124,4 +124,4 @@ Now those changes will be selectively merged into your current working directory [](https://awscommunity.social/@Ric) [](https://gitlab.com/ric_harvey) [](https://www.linkedin.com/in/richarvey/)
-

Git Guide by Ric Harvey is licensed under CC BY-NC 4.0

\ No newline at end of file +[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") \ No newline at end of file