Git Flashcards
What is SCM?
Source Control Management; also as Version Control System, VCS
Why is Github a DVCS?
It is a Distributed Version Control System because it does not have a main central repo.
How to create a git repo in your local directory?
$ git init
- This command creates a hidden directory called .git in your current directory
- Note not to create nested git repo, delete the .git dir. if it is already under a dir. with .git
What does .gitignore do?
When you create the .gitignore file under your local git repo, Github will not allow any files you specify in .gitignore to be uploaded.
**always create .gitignore when you initiate a repo
What does $ git status do?
It tells about our working tree & staging area:
1) Which branch and branch name you’re on
2) If there are files that are untracked (and advise to “$ git add” file)
3) Changes to be committed (Staged files that are waiting to be committed)
What is a “commit” in Git?
A commit is a bundle of changes:
Addition of new files / deletion of existing files/ moving pushing pulling merging commits around.
How to stage files in your git repo? LOCALLY
What does staging a file mean?
$ git add FILE.txt FILE2.md
Staging is like a warehouse that your file is ready to be committed but also available to be changed. If you change the files, you need to stage them again.
How to commit a file in Git? LOCALLY
$ git commit -m ‘Add first project files’
The flag “-m” is about attaching a message to the commit. It is like a explaining tag for that particular changes.
How do you check your history of commits?
$ git log
** Having a good commit hygiene is important at work. One commit should represent one thing, e.g. a bug fixed, a feature added, etc.
What is branching? What is your default branch?
The default branch name is “master”.
We create a new branch - or fork it from an existing branch. The new branch contains the past history of the old branch and from that point on, the log history of two branches will be different.
If the new branch of codes fail, you delete it; if it works, you merge back to the master branch.
**Only commits are forked and merged but not the staged files
How do you link your local repo to remote repo on Github?
$ git remote add origin https://github.com//repo_name.git
git remote => command to work with remote repo
add => link the local repo to remote repo // you can also execute remove/ modify
origin => alias for Github remote repo; it’s a convention to name its ‘origin’ on Github. You can name it whatever you like in this command but origin usually means the central remote repo.
How to push commits to Github remote repo?
$ git push -u origin master
git push => primary command to push commits to remote repo
-u => set upstream tracking branch // link local master branch to remote master branch (from now on, you’ve tracked local branch to a specific remote branch)
origin => alias of remote repo
master => remote repo branch
How to pull commits from Github remote repo?
1) Fetch the changed repo to our local repo
$ git fetch (need to specify branch if not specified previously)
2) Check the difference between the downloads and local repo.
$ git diff master origin/master
=> the first master is your local master branch ; the second one is the master branch in remote origin repo.
3) Pull the repo into your local repo finally
$ git pull (if branch not tracked, $ git pull origin master)
What does $ git diff do?
It provides to compare the first repo and second repo you specify in later arguments.
=> $ git diff master origin/master