Thursday, 14 May 2015

Basic GIT commands


1. Merge sandeepnew branch to dev-new branch

git checkout dev-new
git pull origin dev-new
git merge sandeepnew
git push origin dev-new

2. Resolve a conflict

Manually remove head
git add <filename>
git commit <filename> -m "commit message"
git push

3. Create a new branch with existing branch (xyz)

git checkout xyz //go to xyz branch
git checkout -b <new branch name>
git push origin <new branch name>

4. Delete a branch

//delete local branch
git branch -d <branch name>
//delete remote branch
git push origin --delete <branch name>


5. Force delete a branch

git branch -D <branch name>

6. Revert to some previous commit

git revert <commit ID>
git commit -am "rever back"
git push origin master

###### Another way ######
git reset --hard <commit ID>
git push -f origin master

7. Git cherry pick will be used to pick some commits


8. you need to resolve your current index [error solved] (this will reset branch to before merging states)

git reset --merge

9. Reset sub module (submodule conflict error)=> go to sub module and run below command

git reset HEAD subby

10. Cloning remote branch to local branch

git clone git@github.com:Timescity/TcModels.git


11. Get sub branchs

git checkout -b branchname origin/branchname


12. See all remote branches

git branch -a

13. Update local branch forcefully

git fetch --all
git reset --hard origin/master


14 .gitignore fixes

git rm -r --cached .
git add .
git commit -m "fixed untracked files"


15. create a branch from previous commit

git branch <new_branch_name> <commit_id>
git push origin <new_branch_name>

16. Git clone with submodules

git clone --recursive git://github.com/foo/bar.git

If main module is already there

git submodule update --init --recursive

17. git rename a file

git mv <old-file-name> <new-file-name>
git commit -m "<commit message>"
git push origin <branch-name>

No comments:

Post a Comment