Git Reference


git add "file_name.txt" 

This will add this file to the staging area so it can start to be tracked


git add "directory_path" 

This will add all the files in this directory recursively


git add . 

This will add all new and modified (not deleted) files to the staging area


git add -u 

This will add all modified and deleted (not new) files to the staging area


git add -A 
git add --all

This will add all new, modified and deleted files to the staging area


git branch 

This will tell you which branch is currently active


git branch "branch_name" 

This creates a new branch called "branch_name"


git branch -d "branch_name" 

??


git checkout <filename.txt> 

This will delete any changes and restore the file back to the last checked in version in your local depository


git checkout "branch_name" 

This will switch to the branch called "branch_name"


git checkout -b "branch_name" 

This is shorthand for:

git branch "branch_name" 
git checkout "branch_name"

git checkout -f 

This will remove all your changes


git cherry pick 

?? relating to GUID of previous commits ??


git clone https://github.com/blah/blah 

This pulls out a copy from the remote repository to your local repository and checks out a working directory


git commit -m "my comment" 

This will commit the local changes in the staging area to the local repository


git commit -am "my comment" 

This will commit the local changes to the local repository
This is shorthand for:

git add . 
git commit -m "my comment"

git diff 

This will compare the files in the working directory with the files in the staging area

git diff --staged 

This will compare the files in the staging area with the files in the local repository.


git fetch 

This will update your local git repository with any changes that are new on the server


git gc 

??


git init 

This will initialize your working directory.


git log 

This displays a list of all the changes that have been committed in the corresponding order press "q" to exit this log


git merge 

??


git push -u "remote_name" "branch_name" 

This will push the changes in your local repository to the remote repository


git pull "remote_name" "branch_name" 

This will pull changes from the remote repository to your local repository


git pull --rebase 

The rebase options tells Git to move all the commits to the top of the branch after synchronising it with the changes from the central repository


git rebase --abort 

??


git rebase --continue 

??


git remote add "remote_name" "remote_location" 

This adds a relationship between a remote_name and its corresponding remote_location The remote is only known as used locally


git remote rm "remote_name" 

This will remove a particular remote


git reset HEAD filename.txt 

This will remote a file from the staging area


git reset --hard origin/master 

Throw away all my stages and unstaged changes and ignore everything in my local branch.
Make my local branch exactly the same as the remote repository


git reset --soft HEAD~1 

??


git status 

This will tell you what the current status is for the project


git status -s 

Provides a short compact status for the project


vim ?? 

??



Rebaising
There are two main ways to integrate changes from one branch into another - the merge and the rebase



Online References:

https://try.github.io/levels/1/challenges/1
https://git-scm.com/book/en/v2/Git-Basics-Getting-a-Git-Repository
https://confluence.atlassian.com/bitbucketserver/basic-git-commands-776639767.html
https://confluence.barcapint.com/display/RnADevOps/Set+your+local+Git+configuration


© 2020 Better Solutions Limited. All Rights Reserved. © 2020 Better Solutions Limited TopPrevNext