Professional Documents
Culture Documents
of Combined
Git
WHAT IS VERSION CONTROL
WHAT IS GIT
INSTALLING GIT (COMMAND LINE AND GUI OPTIONS)
BASIC GIT COMMANDS TO GET STARTED
INSPECTING A REPOSITORY
FILE OPERATIONS
UNDOING COMMITS & CHANGES
REWRITING HISTORY
BRANCHES
MERGING
REBASING
STASHING
CONFLICTS
SUBTREES AND SUBMODULES
SOURCE: https://github.com/weeyin83/14daysofgit
@arjun-panwar
12 Days
of Git
DAY 2
BASIC GIT COMMANDS
@arjun-panwar
Git Clone
Git clone is the command that will help you download an existing
remote repository (like GitHub for example) to your machine.
For example if you head over to any GitHub repository and click on the
green Code button. It will display a URL. Take a copy of that URL.
Git add
When we work on a local copy of a repository we will be creating,
modifying, or delete files. When we do that we need to add those
changes to our next commit so they are copied to the remote
repository.
Git add starts to prepare our changes ready to be saved and sent
to the remote repository.
Or we can add all the files and changes we made with the
command:
Git commit
First of it it gets the updates from the remote repository (git fetch)
Applies the changes to your local copy of the repository (git merge
There are times when you will use this command it will throw up
errors or conflicts that you need to resolve but it will pull down any
changes for you.
Git init
Git init can convert an existing project or folder into a Git
repository.
Most git commands are not available until a repository is initialised,
so typically this is the first command you will run when starting a
new project on your local machine.
When you use git init it create a .git subdirectory in the working
directory. This contains all the necessary Git metadata for the new
repository.
You can use git init in a couple of way.
If you have an existing folder structure with files and code within it
that you want to turn it into a git repository you can issue the
command:
If you haven't created a folder or started creating any code you can
issue the following command to create the folder and initialise it as
a git repository:
For more visit:
https://www.techielass.com/basic-git-commands-to-get-started/
12 Days
of Git
DAY3
INSPECT A GIT REPOSITORY
@arjun-panwar
There are times when you will want
to check the status of a repository
on your local machine, or when you
want to look back at the history.
Git status won't show you the commit history of the repository though.
It also shows that changes on the local repository that should be
pushed to the remote repository.
Git log
Git log is the command you want to use to see the repositories
commit history.
The space bar to help you scroll down and you can exit it using q.
@arjun-panwar
Rename a file
Git mv is the command that can help you with renaming. We do need to
understand what this command does though.
Git mv -k
The -k option allows Git to skip over any erroneous conditions resulting
from a git mv call. For example, if you are trying to move a file to
another location and that file already exists the command would error
out. If you don't want to see that error and have Git move onto your
next instruction you should use the -k option.
Git mv -n
The -n option is actually short for --dry-run. It won't actually carry out
the move or rename, it will just show you what would happen if you did
perform the command.
Git mv -v
The last option is the verbose option. Using this option will give you
more information and feedback when you execute the command.
For more visit:
https://git-scm.com/docs/git-mv
12 Days
of Git
DAY 5
UNDOING COMMITS & CHANGES
@arjun-panwar
Undoing
commits & changes
It's important to remember with this command, you are only reverting
the commit you aren't erasing the history of the commit. So, any
changes can still be referenced within the history of the repository.
Git Reset
With Git revert we just undid changes from a specific
commit. However, there might be occasions where you
want to revert every change that has happened since a
given commit.
This is where the git reset command can be used.
1.
Again, with the git reset command remember that you are just
reverting to a previous state, you aren't removing the history. It will
still be there to see and refer to.
For more visit:
https://www.techielass.com/undoing-commits-changes/
12 Days
of Git
DAY 6
REWRITING GIT HISTORY
@arjun-panwar
Rewriting History
Change most recent Git commit message
There are times when you make a commit but realise you've
written the wrong thing within the commit message. What do
you do?
This is another use case for the git commit --amend command.
Your workflow might be:
1. Make changes to file 1 and file 2
2. Add and commit those changes
3. Realise you've forgotten to add a small change into file 1
4. Make the additional change
5. Use the command git commit --amend --no-edit
I would caution using this option and only using it on your own
commits, don't confuse others by amending other people's commits
For more visit:
https://www.techielass.com/rewriting-git-history/
@arjun-panwar
What are Git branches?
Using HEAD
Referencing HEAD saves you from having to type out the exact
name of the branch.
When you issue this command you may receive merge conflicts,
we will be looking at how to deal with them in coming days.
If you want to delete a branch that has already been merged you
can use the command:
@arjun-panwar
What is merging?
You can merge more than one branch at a time. There could
be conflicts and issues when doing so, and we'll be looking
in future.
@arjun-panwar
What is Git Rebasing?
@arjun-panwar
What is a git stash?
@arjun-panwar
What are Git conflicts?
As we've seen Git can handle merges
automatically most of the time. Git
conflicts arises when two separate
branches have made edits to the same line
within a file or even when a file has been
deleted in one branch and changed in
another.
@arjun-panwar
What is a git submodule?
Git submodules allow you incorporate and
track version history of external code.
Sometimes what you are working on, will
depend upon external code. You could just
copy and paste that external code into
your main repository and use it. But there
is the obvious disadvantage here of having
too manually maintain that code and grab
updates when they arise.
You could use something like a package
management system to help maintain the
code, Ruby Gems or NPM. But again, there
are downsides to this approach as well.
Neither of these methods incorporate
methods to track edits and changes of the
external repository.
A Git submodule is a recording within a Git
repository that points to a specific commit
in another external repository.
Submodules are static and only track
specific commits, they don't track git refs
or branches. And don't automatically
update when the external repository is
updated.
When should I use a git submodule?
@arjun-panwar