Git - DVCS



Created an account in github.com
Password is my facebook account password.

GIT - Allows groups of people to work on the same documents (often code) at the same time, and without stepping on each other's toes. It's a distributed version control system.

Platform: Windows 10

git init - Initialize empty Git repository
git remote add origin <link> - Add remote repo. In my case GitHub.
git pull origin master - pulls the code from central/remote repo.
git push - Pushes all the code to central repo.

git status - Used to check the files that are ready to add to local repo.
git add - Add the files to staging area
git add -A - To add multiple files or folders to the staging area
git commit -a -m "" - Commit multiple files and folders to the local repo
git log - Shows all the info about commit

Branches

git branch firstbranch - create a branch named as firstbranch from the master branch (trunk in case of SVN)
git checkout firstbranch - Switch to the branch firstbranch
ls - list all the files in particular branch or master

Merging

git merge firstbranch - while merging we should always be in the destination branch and do the operation

Difference between git pull and git fetch

git pull actually pulls out all the code from remote repo to your local repo whereas git fetch will also pull out all the code from remote repo but to a different branch. we should later merge the code back to the local master repo in the case of git fetch.

git fetch = git pull + merge

How to push code to remote repo

ssh-keygen - generate a public key and add it to github -> Settings -> ssh keys
ssh -T git@github.com - Does ssh authentication. Check in Settings in github whether the ssh key is activated. It turns the key to Green
git push origin firstbranch - Pushes all the files of branch firstbranch to remote repo
git push origin master - Pushes all the files of master branch to remote repo

git checkout [first 8 digits of commit hash] revert.txt - Reverts the file to the previous version

Comments

Popular posts from this blog

Bash - Execute Pl/Sql script from Shell script

Gradle Fundamentals

Load Balancing using Spring Cloud Netflix Ribbon