In the previous post we went through some concepts and terminology in git.
Some basic git commands
Create a repository
Let us take a look at how we can create a local repository.
What does it do?
- Initialises a repository for a project
- Creates a .git folder for your repository
- Used by Git to track changes that happen in that repository folder
- Git stores repository specific settings to that folder
- It tracks the latest change in a branch in that folder
- Also stores configuration for the repository in there
A new repository, needs some configuration. Let us go ahead and configure it.
- Configuration can be
- Local (repo specific) or global (system wide)
- Stores information about
- Your name, email etc.
- Remotes (talk about that soon)
- Aliases (talk about that soon)
Status check - Where’s my local at?
A file that is not yet in the repository
Are those that were already committed to the git repository and have been changed since.
Staging changes to commit
git add . – Stage all files in this directory that have changed for commit
- Or if you want to be specific and stage only one or two files among several, then
git add filename.extension
- When you run
git commit, staged files are picked to be committed
- Your GUI for GIT might offer to automatically stage any unstaged files for you
So what does a commit do?
- Record changes to your local git database
- choose files you want to be part of the commit
- then make the commit with a description that is comprehendable by your collaborators
- running the commit command will open up the editor you configured while setting up git
git commit opened up
vscode which is my default git editor. it might open another editor for you, depending on which one you chose as your default editor when installing Git.
As you finish your commit message and close your editor, you get the status of it in your git bash session.
That’s cool but where do I see all commits?
There are many ways to display your history of commits
- One liners only
- Detailed information
- Certain format of dates etc.
git logtakes in a variety of options.
Let us explore branching in the next post