-
git help <command_name> -
To set username:
git config --global user.name "Gourav Chawla" git config --global user.email anything@exampledomain.com-
Check already present usernames:
git config user.name -
Check usernames and email address:
git config --list -
Also, you can view it in the
~/.gitconfigfile
-
NOTE: The above configurations are for every git project. You can also change them on a project by project basis.
-
Initialize new git repo in current directory :
git init -
To check status of files in repo (commited, modified etc) :
git status -
To add files to staging area :
git add index.html(file name)- Add directory to staging area
:
git add css(directory name)
- Add directory to staging area
:
-
To commit a file :
git commit -m index.html -
To show the commit history (How many commits and which commits) :
git log
-
To find what changes has been made to a file; Lines added or removed :
git diff -
To see changes if file has been staged :
git diff --staged -
To unstage file :
git reset HEAD <filename> -
To commit a tracked file(Already staged file, skip staging and commit)
git commit -a -m "Modify index.html" git commit -am "Modify index.html" -
To add files to last commit. Made commit but forgot add a file. So, now to amend commit: :
git commit --amend -m "Modify index.html & cats.html" -
To undo commit and add back to staging area :
git reset --soft HEAD^ -
Adding a remote :
git remote add origin https://github.com/gregg/git-real.git- Remove Remote:
git remote remove <remote_name>
- Remove Remote:
-
To push the changes to remote :
git push -u origin master (origin: remote repo name; master: local branch to push)
-
Clone a repo :
git clone url <folder_name> -
Check the remotes :
git remote -v -
Create a branch to work on a different feature :
git branch grooming(name of branch) -
Switch to branch grooming :
git checkout grooming- Checkout and create branch
:
git checkout -b <branch name>
- Checkout and create branch
:
-
Merge branch into master :
git merge grooming -
Clean up the branch/ delete it :
git branch -d <branch_name>
-
Remove files after updated gitignore :
git rm -r --cached .Before doing this you should commit all the changes that are not commited. Then do
git add .to add all the files minus the files in gitignore. Commit and you are good to go. -
Unstage files :
git reset filename -
Rebase tutorial :
https://asciinema.org/a/78683 -
See log in one line :
git log --oneline -
Stash (Problem statement)
git stash git pull origin master git stash pop -
Undo rebase (Reflog & hard reset)