Git and Github
Git and Github
Git is a version control software. In one way or the other you may need to use a git and a
GitHub together.
1. Install Git
First, you need to install the version control software, Git.
initiated
modified
staged
We can write the command git status at any time. It is a means to to check what is
happening on your project.
7. Git status:
It shows the status of all files in each area, like which files are untracked, which are
modified, which are staged etc.
8. Git status
on branch master Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git restore ..." to discard changes in working directory)
modified: a.txt
modified: b.txt.
no changes added to commit (use "git add" and/or "git commit -a")
git status -s
9. Git commit:
git commit -am 'commit message’.
git commit -m "Your Message here" (commit your changes, attach a message, create
save point)
git commit -a -m "commit message”.
-a means adding files to staging area
-m means commit message, but this command will work only for tracked files but not
for new files.
git commit -am "commit message"-> Valid.
10. Git log:
It shows history of all commits. It provides commit id, author name, maild , timestamp
and commit message.
git log
git log –help
11. Git Checkout
We can use checkout command to discard unstanged changes in the tracked files of
working directory. Observe the 3 words:
1) Only for working directory
2) To discard unstaged changes(The changes which are not added to staging area)
3) In the tracked files (The files which are already added to staging area/commit)
C:\Users\eraysub\subrata\subrata1>git init
cd C:\Users\eraysub\subrata\subrata1\rhcsa9
git log
C:\Users\eraysub\subrata\subrata1\rhcsa9>git remote -v
Set up:
git config --global user.name "User Name"
git config --global user.email email@email.com
Delete a file
git rm <filename> = deletes a file, updates git and then commit!
git rm --cached <filename>" = delete a previously tracked file
Check difference
git diff= displays what will be added if i git add, so what changed
in the folder and hasn't been updated yet
git diff <filename> = displays the alterations of a file (the modified
and the commited versions of it)
git diff --staged = displays what has already been added and thus
what changed will be recorded
git diff HEAD = displays changes since last commit
Display history
git-log = displays the history, the chronologival order of commits (based
on their IDs), who did them, what was their description
git show <id> = displays what the commit did = git log + git diff
Cancel not staged changes.
git checkout = it copies staging area (usually last commit) to out working
copy.
Reset
git reset- remove all that exists in my staging area by copying them from
the most recent commit (basically undoes git add)
Combinations
git commit -a = git add + git commit (not desirable due to lack of
control)
git pull = git fetch + git merge (very useful)
Collaborate
Show remote: git remote
Add remote upstream from GitHub project: git remote add upstream
https://github.com/user/project.git