Git Notes

5
0
## Global Configuration
# Enable color console
git config --global color.ui auto

# Set meld as the diff tool
git config --global diff.tool meld

Configuration

# Convert a non-bare repository into a bare one
git config --bool core.bare true

Commit

# To edit last commit log (and possibly change
# the author data if it was changed)
git commit --amend --reset-author

Commit in the past

MYDATE='1999-12-31T23:59:59'
GIT_AUTHOR_DATE=$MYDATE GIT_COMMITTER_DATE=$MYDATE git commit -m 'bla bla bla''

Delete a commit

Revert to the previous commit

git reset --hard HEAD~1

Push the deletion if commit was previously pushed

git push --force

Remove files

# Remove untracked files and directories (not ignored)
git clean -f -d

# Remove untracked files and directories including ignored ones) 
git clean -f -x

# Remove ignored files
git clean -f -X	

Staging

git add				# Stage a file
git add --all		# Also stage deleted files

# Changed or new not ignored. Deleted files not staged
git add . 

# Stage currently tracked files (Not adding files )
git add -u

# Equivalent to all above
git add -A 

# Unstage a file
git reset HEAD 

Remove Files

git rm --cached  # Remove from git database but not from the filesystem

Revert

To revert a single file

git checkout -- src/com/mmonem/erp/server/service/LoginServiceImpl.java

Revert all

git checkout . -f

Branching and Merging

# List all branches:
git branch -a

# List remote branches:
git branch -r

# Switch to a branche
git checkout TheBranche

# Switched to a new branch
git checkout -b NEW_BRANCHE_NAME

# Or:
git branch NEW_BRANCHE_NAME
git checkout NEW_BRANCHE_NAME

# Delete a branch
git branch -d BRANCHE_NAME

Remotes

Show Remotes

git remote -v
git remote show origin

Adding a Remote

git remote add  

Change Remote URL

git remote set-url origin 

Setting upstream

Verify that the remote is fetched first

git branch --set-upstream-to=origin/master

Pushing

git push --all -u
git push --tags
git push  
git push   : 

Delete a remote branch

git push origin --delete 

or

git push origin :

Copy remote branch into another remote branch

git push origin origin/:refs/heads/

Rename a remote branch

git push origin :old new

Reflect deletion of remote branches into the local database

git fetch [remote] -p

Discovery

git ls-files
git ls-files -m # List modified files only
git branch -a

Cloning

# All branches, all history
git clone  [local_dir]

# Specific branche
git clone -b  

# Not all history
git clone --depth 1  

# Into another bare repo
git clone --bare . /other/dir/name.git

Sparse Configuration for Existing Repos

# Enable sparse configuration
git config core.sparsecheckout true

# Set what do you want to track
echo some/dir/ >> .git/info/sparse-checkout
echo another/dir >> .git/info/sparse-checkout

# And finally
git read-tree -mu HEAD

 

Comments

عبد المنعم 8 year ago
ايه!!!!!
أم العيال 8 year ago
من فضلك ترجم
زغباوية 8 year ago
انزل بالترجمة!!!
M.Bastaka 8 year ago
We missed these notes since your departure BASTAKA
محمد عبد المنعم 8 year ago
Here we can bring back all those moments 🙂
زغباوية 6 year ago
ويلكم 🙂
zedony.com - A mmonem.com production. Privacy Policy