Git Summary

keikis org Jun 15, 2018 @ 1:30 pm

Git Summary

WORKING WITH BRANCHES

//Show all branches, locals & remotes

git branch -a

//Show only locals

git branch

//checkout remote branch

git checkout -b origin/branch_1

//update

git pull origin branch_1

//Branch serverfix set up to track remote branch refs/remotes/origin/serverfix.

//Switched to a new branch “serverfix”Switched”

git checkout -b serverfix origin/serverfix

//Create branch

git checkout -b newbranch

RESET TO MASTER. DISCARD LOCAL COMMITS

//Reset to master. Lost all commits

git checkout master

git reset –hard origin/master

Commit your changes or stash

Commit your changes or stash them before you can merge

Options:

1. Commit the updates

git commit -m "My message"

2. Stash the changes

Stashing acts as a stack, where you can push changes, and you pop them in reverse order.

Stach your local uncommitted changes on that branch.

git stash 

Pull and merge to locally committed changes on that branch (give this merge some message, and fix conflicts if any.)

git pull origin branch_name -v 

Pop, get the stashed changes. Then you can make commits on popped files if you want or push already committed changes First and make new commit to files later.

git stash pop

Pushing the merged changes.

git push origin branch_name -v 

3. Discard the local changes

As we can see before using a hard reset:

git reset --hard.

Other way with identical results:

git checkout -t -f remote/branch

 

REMOVING LOCAL FILES WITHOUT TRACKING 

From the current working tree of Git

git clean -n

Clean step: be careful: this will delete the files:

git clean -f

To remove directories,

git clean -f -d or git clean -fd

To delete ignored files,

git clean -f -X or git clean -fX

To delete ignored and not ignored files,

git clean -f -x or git clean -fx

 

VIEW LOGS, FILTER BY BUILD & CHECKOUT COMMIT

//To search the commit log (across all branches) for the given text

git log –all –grep=’Build 0051′

//To search the actual content of commits through a repo’s history, use

git grep ‘Build 0051’ $(git rev-list –all)

//Checkout by commit id

git checkout 2f787bb5c107f25e5576817413c514a9006bb70e

WORKING WITH LOGS/VERSIONS

//Show last day commit

git log -1 –format=%cd

WORKING WITH  BRANCHES & MERGES

//Return to principal branch

git checkout master

//Delete newbranch

git branch -d newbranch

//Push / public a branch to remote server

git push origin <branch>

// Add remote to origin

git remote add origin <server>

//Send changes to remote

git push origin master

Merge Branches

//update local repository to last commits

git pull

//fusion other branch with the active

git merge <branch>

//mark files to fusion

git add <filename>

//Review changes before fusion

git diff <source_branch> <target_branch>

WORKING WITH TAGS/VERSIONS

//Tagging particular point

git tag -a v1.0 -m ‘Version 1.0’

//Get to local a determinate tag/version

git checkout tags/v1.0

//Same before but creating a new branch

git checkout tags/v1.0 -b NewBranch

//You can go back to another branch (for example master)

git checkout master

GIT PROXY

//Config Global proxy URLs

git config –global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080

//Reset this proxy and work without proxy

git config –global –unset http.proxy

//check the currently set proxy

git config –global –get http.proxy

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
Social media & sharing icons powered by UltimatelySocial