# to create a new branch and checkout to that branch
git branch new-feature
git checkout new-feature
#to checkout a new branch
git checkout -b <branch name>
# to see all branches checkout out
git branch
# to switch to another branch (just do not use the -b option)
git checkout <branch name>
# To add a user to the git global config, before commit and push.
# This will create the profile in ~/.gitconfig
git config --global user.email "develamit@gmail.com"
git config --global user.name "develamit"
# To add a user locally - this will create the user profile in .git/config
git config user.name develamit
git config user.email develamit@gmail.com
# For git submodule:
https://github.com/blog/2104-working-with-submodules
# For git pull request
https://help.github.com/articles/creating-a-pull-request/
#You can store your credentials using the following command, so that it does not ask for username,
password everytime
git config credential.helper store
git push http://example.com/repo.git
Username: <type your username>
Password: <type your password>
# to change the commit user
git commit --amend --author="John Doe <john@doe.org>"
#If you want to overwrite only one file:
git fetch
git checkout origin/master <filepath>
#If you want to overwrite all changed files:
git fetch
git reset --hard origin/master
# after adding a file, if you want to revert back
git reset HEAD <file name>
Duplicating an old repo to a new repo
# First create a bare clone of the old repository
$ git clone --bare https://github.com/exampleuser/old-repository.git
# Mirror-push to the new repository
$ cd old-repository.git
$ git push --mirror https://github.com/exampleuser/new-repository.git
# remove the temporary old local repository
$ cd ..
$ rm -rf old-repository.git
RESETTING TO A COMMIT
# Ensure you have no uncommitted changes that you want to keep
git reset --hard 56e05fced
# Move the branch pointer back to the previous HEAD
git reset --soft HEAD@{1}
git commit -m "Revert to 56e05fced"
TAGGING
# add
git add .
# show tags
git tag -l
# create tag
git tag -a v1.4 -m "my version 1.4"
# tagging later
git log --pretty=oneline
git tag -a v1.2 9fceb02 (this is the hash number)
# show
git show v1.4-lw
# commit
git commit -m "message that tagging has been done"
# Sharing tags in repo
git push origin master v1.5
# To see the tags in the remote, do
git fetch
.gitignore
If you already have any bin folders in your git index which you no longer wish to track then you
need to remove them explicitly. Git won't stop tracking paths that are already being tracked just
because they now match a new .gitignore pattern. Execute a folder remove (rm) from index only (--cached)
recursivelly (-r). Command line example for root bin folder:
git rm -r --cached bin
After this step, if bin/ is mentioned in .gitignore then it will not get checked in
UPDATE BRANCHES
# If locally you do not get to see all the branches, do the following
git remote update
git fetch
GitFlow
# install on Mac
sudo port install git-flow
# Initialize Git Flow on an existing git repo (that has been cloned locally)
git flow init
# To list/start/finish feature branches, use:
git flow feature
git flow feature start <name> [<base>]
git flow feature finish <name>
Git LFS (large file system)
# assuming sudo su (root) session - did this in a docker container
apt-get install software-properties-common
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash
apt-get update
apt-get install git-lfs
git lfs install
vim .git/config
git lfs status