This is collaboration of all resources, hands-on activities and experiences. This is not some code base, Purpose of this is to keep on learning git down the line and keep all resources at a safe place so it will be helpful further for relearn or troubleshoot purposes.
- Cheatsheets
- Atlassian Cheatsheet: A brief cheetsheet including main commands. Altassian Cheatsheet
- Git Tower Cheatsheet Bundle: A collection of cheatsheets, nicely structured. Git Tower Cheatsheet
- Merge
- Stash
- Revert
- Markdown (.md) File Syntax
- Submodules
- Template - README.md file
These cheatsheets contain basic to advance level git commands that will enable you to master/troubleshoot git. Git command line is very vast and advanced which may include several scenarios. While cheatsheet by Atlassian is handy one page to use on your normal day to day needs, Git tower has collection of documents to help get rid of any riddle that might come.
Merging is Git's way of putting a forked history back together again. The git merge command lets you take the independent lines of development created by git branch and integrate them into a single branch.
A nice explaination, Git Merge
//TODO: continue
Often, when you’ve been working on part of your project, things are in a messy state and you want to switch branches for a bit to work on something else. The problem is, you don’t want to do a commit of half-done work just so you can get back to this point later.
- Use
git stash
to push new stash onto your stack. - Now your working directory will be clean, you can switch to another branches as well.
- You can use
git stash list
to see the list of all stashes. For example: example-stash-1 - Use
git stash apply
to bring all changes back to working directory, top most stash. - Use
git stash apply <stash>
to bring all changes back to working directory, stash whichever mentioned. For example: example-stash-2
// EXAMPLE-STASH-1: get list of all stashes
$ git stash list
stash@{0}: WIP on master: 049d078 added the index file
stash@{1}: WIP on master: c264051 Revert "added file_size"
stash@{2}: WIP on master: 21d80a5 added number to log
// EXAMPLE-STASH-2: apply stash to particular stash
$ git stash apply stash@{2}
The git revert command can be considered an 'undo' type command, however, it is not a traditional undo operation. Instead of removing the commit from the project history, it figures out how to invert the changes introduced by the commit and appends a new commit with the resulting inverse content.
A nice explaination, Git Revert
Please find link below to learn more about how to write markdown files. The purpose of writing markdown files is they are simple and can contain wide variety of information that may need for present some document about any repository or project.
- The purpose of git submodules is to have an independent another git repository within a git repository.
- Suppose, in your project you have some submodule which exists as an independent git repository or project. A plugin may be.
- Another use which I see to manage git account by clubbing similar set of repository. (i.e. some ES6 repo may be part of JS).
- To add any repository as submodule, clone it inside repository normally
git clone https://github.com/repo-sub-module.git
- Use
git status
you will be able to see added repository asuntracked folder/files
- Instead of using
git add repo-sub-module
usegit submodule add https://github.com/repo-sub-module.git
- Now it has been added as submodule and a new file will be generated
.gitmodules
. Which will keep info about sub modules. - Note that now it is independent submodule. It can independently progress.
- If some changes have been made in submodule. You have to pull submodule to local and then merge/commit in submodule directory as well as parent directory.
- Only commiting on parent's git will not affect submodule's git.
- While cloning parent if you want to clone submodules also use
git clone --recursive https://git-hub.com/parent-repo-with-sub-modules.git
- When you go into submodule directory, you will find
HEAD
indetached
state. You cangit checkout master
toattach HEAD
to branch.
There are some great tools available to help you in learning process. Best things they offer are
- Visulaization of every step.
- Minimal, to keep focused over one activity at a time.
- You can choose your own pace.
Some templates that are ready to use and will give ideas about best practices to follow: