Brief description about GIT
1) git config –global user.name Ameer
2) git config –global user.email Ameer@webnoid.com
3) git config –global core.editor vim
4) git config –global alias.st status (or) git config –global alias.co checkout
When you clone repository from remote.
1) git clone <remote url>
After doing certain changes in code
To add code to staging
1) git add .
To commit all the staged files into local repository
1) git commit -m “all”
To push all committed files into Master (GitHub)
1) git push origin
To commit code through editor
————————————-
1) git commit
It opens default editor, there we need to write message and it shows all modified files in that text editor.
2) git commit -a (commits all modifications which had done in the working copy)
First time to create GIT Repository
—————————————–
git init
git remote
———-
1) To list remote connections
git remote
2) List remote connections with url
git remote -v
3) To create a new connection to a remote repository ,After adding remote ,you can use <name> as a convenient shortcut for <url> in other git commands.
git remote add raj <url> [syntax : git remote add <name> <url> ]
4) To remove connection to the remote repository
git remote rm <name>
5) Rename a remote connection name from old to new
git remote rename <old name> <new-name>
git Fetch
———-
“git fetch” command imports commits from a remote repository into your local repository.The resulting commits are stored as remote branches instead of the normal local branches that which we have working with.By fetching it will not make any effect on your local repository.It is same like “svn update” command.
To fetch all of the branches from the repository and to get all the committed files from other repository.
1) git fetch <remote>
ex: git fetch origin
output:
#origin/master
#origin/developer
#origin/Login-form
To fetch only specific branch
1) git fetch <remote> <branch>
Remote Branches
———————-
Remote branches are just like local branches except that it will show some body else commits of other repositories also.You can see them as read only branches.
to view remote remote branches we need to keep -r flag to git branch command.
1) git branch -r
#origin/master
#origin/developer
#origin/Login-form
we can check these branches with commands git checkout and git log. After approving the changes which are there in the remote branch,Then only you can merge code into your local branch with command “git merge”.
To see what commits have been made to the upstream master, we can use below command
1) git log –online master ..origin/master
To approve changes and merge them into your local master branch
- git checkout master
- git log origin/master
Then to merge
git merge origin/master
Git Pull
———
We have seen Merging upstream changes in to local repository with git fetch and git merge but git pull roll this in to a single command
Fetch the specified remote branch of the current branch and immediately merge into local copy.(same as git fetch <remote> and git merge origin/<current-branch>)
1)git pull <remote>
Instead of using git merge to integrate remote branch in to local branch.we can use “git –rebase”
1)git pull –rebase <remote>
Git fetch reveals the origin’s version of the master as discussed earlier,The git merge immediately integrates the remote master.
Git Pull via Re-base
——————-
–rebase is used to ensure a linear history by preventing unnecessary merge commits.(A linear history is simply a Git history in which all commits come after one another. I.e. you will not find any merges of branches with independent commit histories)
## Most of them prefer rebase over merging ##
If I want to put my changes on top of what everybody else has done.use git pull with –rebase flag
git config –global branch.autosetuprebase always
The above command will integrate via git rebase instead of git merge
ex:
1)git checkout master
2)git pull –rebase origin (simply moves your changes on top of what everybody else had done)
Git Push(to publish your local changes to central repository)
————————————————————-
Git push is to transfer commits from your local repository to remote repository.In simple manner git push exports commits to remote branches.
To push the specified branch to <remote>,along with all of the necessary commits and internal objects.
1)git push <remote> <branch>
2)git push <remote> –force
To push all your local branches to the specified remote.
2)git push <remote> –all
3)git push <remote> –tags
git pull (git pull command is shortcut to the following both commands “git fetch and git merge” )