HEAD is the reference to the most recent commit.In other words, HEAD is the parent of the next commit.
HEAD is the tip of the commit in current branch.
We can view where HEAD points to using:
$ cat .git/HEAD
ref: refs/heads/master
$ cat .git/refs/heads/master
eb7e1080e7843a7a2597e6643bde64cc19b50e4e
We can view where HEAD had previously pointed to using: git reflog
It is the state of files we are currently working on.
Working tree is same as working directory.
Index is a staging area between working tree and the repository.
Index contains a list of files that will be added to the repository if you run git commit command next.
Running git status displays the contents of the index.
Index reflects the state of files in HEAD after we commit.
Before we commit files to the repository, we need to add files to the index using git add
When we run git status we see a list of files in three categories:
-
Files that have been added to the index ( staged,by using
git add) -
Files that are tracked but not added to index.
-
Files that are completely untracked.
Checkout generally means to update files/paths. Depending upon supplied parameters, checkout performs two things:
-
It will switch to a particular branch:
When used as
git checkout <branch>, it will updateHEADto the specified branch and also set that branch as the current branch. This action will effectively switch to a branch. -
It will unmodify a modified file:
When used as
git checkout -- file.txt, it will checkout file.txt out of index to the working directory, any changes to the file in working dir is permanently lost. It effectively copies staged file to in place of the one in working directory.When used as
git checkout HEAD file.txt, it will checkout file.txt out ofHEADto the index and working directory. Any changes tofile.txtis permanently lost.
git reset --hard discard all changes to working directory
git checkout -- file.txt discards changes to file.txt only
git checkout -- * discards all changes to working directory
git reset --soft HEAD~1
Resets the HEAD to secondlast commit (specified here by HEAD~1)
--soft means to leave the changed files untouched.
Using --hard instead removes the changes in file aswell (ie modifies index).
git clean -fd - d flag removes untracked directories in addition to untracked files, f means force , depends upon clean.requireForce config
- Add files to untrack to
.gitignore - Commit all outstanding changes
- Run
git rm -r --cached .so that all ignored files are removed (from the index/staging area) git add .to add filesgit commit -m 'removing untracked files'to commit
git revert HEAD This will reverse the effects of an earlier commit (often a faulty one) and record a new commit. The faulty commit will remain in the log list.
This is the opposite of doing git add file.txt
-
If file is already tracked:
git reset HEAD file.txtReset index entries forfile.txtto its state atHEAD, without touching working tree (ie all changes to the file since last commit remain intact). -
If file is not tracked but is staged:
git rm --cached file.txtRemoves the file from index without touching the working directory.rm file.txtthen removes the file from working directorygit rm -f file.txtRemoves file from both index and working directory (ie combines the effect of two commands from above).
git ls-tree -r master --name-only
Make a pull request [link]
- Fork repository
- Clone repository to local maching using
git clone - Start a new branch using
git checkout -b <branch> - Make changes and commit
- Push branch to github repo using
git push origin <branch> - Go to forked repo in github, select and click on the 'create pull request' button
List branch configurations for push [url]
git remove show origin
