git cheat sheet
git init
for making a git repository
git add
for tracking new files and for staging files
git status
for checking status
git log
for commit history
git commit -m
for adding commit msg on terminal
git commit -a
for direct saving and skipping staging area
git log -p
for seeing full explained changes in files p stands for patch.......exit by pressing q
git show
then write ID to see specific commit
git log --stat
for statistics on the commit
git diff
review changes before officially staging and committing them..add a parameter for specific file if want to see change in that SHOWS CHANGES THAT HAVE NOT BEEN STAGED YET!!
git add -p
tells us to see and review changes before staging them
git diff --staged
review changes that have been cstaged but not committed
ls -l
list files
git rm
then enter file name for removing file
git mv
then enter file name (space) new file name ...for renaming file or moving file from one repository to another
.gitignore for ignoring certain file during git status OR ls -l ..example.. echo .DS_STORE > .gitignore ...use ls -la to see all files including ignored files git checkout to revert unstaged changes USE -p flag which will ask change by change if you want to revert the change git reset counter part to 'add'..for reverting changes which have been staged git reset -p this asks change by change, the change we want to unstage git add * for staging all the existing files in the repositry git commit --amend allows us to modify and add changes to the most recent commit. git commit --amend command__ allows us to modify and add changes to the most recent commit message. git revert for rollbacks...it will create a new commit that is the opposite of the given commit git branch for seeing branches and their status git branch then a NAME of new branch for creating a branch git checkout then branch name for shifting to that branch git checkout -b new-branch for creating and shifting to that new branch in one go git branch -d then branch name for deleting that branch git merge then name of new branch for merging it with master branch...we need to be inside the master branch for this of course
GITHUB
git clone followed by URL of the remote repositry for cloning the repositry unto the computer git push for pushing the local changes to the remote repo on github git config --global credential.helper cache for caching password and user name for 15 mins git pull to retreive new changes from the repositry {directly merges them, git fetch doesnt directly do that} git remote -v for seeing push pull info about repo git remote show origin for info on remote repo git branch -r for seeing the remote repo branch currently on git fetch copies the changes made in the remote repo to the remote branches (in our local machine) so that we know what changes others have made...to copy changes in remote to local git log origin/master to see what changes others have made git merge origin/master to megre the changes of the master brach of remote repo to our local branch git remote update If we want to get the contents of remote branches without automatically merging any contents into the local branches, we can call git remote update. git log --graph --oneline --all This graph shows us the different commits and positions in the tree. (Tree of commits on all branches)
CONFLICT: Jis line me mae ne change kiya ussi line me doosrey bandey ne bhi koi aur change kiya. When i tried to merge, git couldn't resolve that conflict.
merging is used for combinig branch data and history together
git commit -a
Stages files automatically
git log -p
Produces patch text
git show
Shows various objects
git diff
Is similar to the Linux diff
command, and can show the differences in various commits
git diff --staged
An alias to --cached, this will show all staged files compared to the named commit
git add -p
Allows a user to interactively review patches to add to the current commit
git mv
Similar to the Linux mv
command, this moves a file
git rm
Similar to the Linux rm
command, this deletes, or removes a file
git checkout is effectively used to switch branches.
git reset basically resets the repo, throwing away some changes. It’s somewhat difficult to understand, so reading the examples in the documentation may be a bit more useful.
There are some other useful articles online, which discuss more aggressive approaches to resetting the repo.
git commit --amend is used to make changes to commits after-the-fact, which can be useful for making notes about a given commit.
git revert makes a new commit which effectively rolls back a previous commit. It’s a bit like an undo command.
There are a few ways you can rollback commits in Git.
There are some interesting considerations about how git object data is stored, such as the usage of sha-1.
Feel free to read more here:
https://en.wikipedia.org/wiki/SHA-1
https://github.blog/2017-03-20-sha-1-collision-detection-on-github-com/
git remote
Lists remote repos
git remote -v
List remote repos verbosely
git remote show
Describes a single remote repo
git remote update
Fetches the most up-to-date objects
git fetch
Downloads specific objects
git branch -r
Lists remote branches; can be combined with other branch arguments to manage remote branches