Basic Git commands

335 views

Published on

Basic Git Command for Beginners

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
335
On SlideShare
0
From Embeds
0
Number of Embeds
46
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Basic Git commands

  1. 1. Basic Git Commands Jitendra Zaa http://JitendraZaa.com
  2. 2. Add Existing folder as a Git repository Navigate to folder where code exist in your command line $ Git init
  3. 3. Add (Index) all existing files in Git repository $ Git add .
  4. 4. Set Global Git Name and Username • Every commit requires to know who is the user committing • So, we need to setup global Name and Username. This is onetime process • $ git config --global user.name 'Your Name' • $ git config --global user.email you@somedomain.com
  5. 5. Commit files added in git index • $ git commit --message “Your Initial Commit Message”
  6. 6. Add remote • Till now all files added and committed are saved on local system • You may want to move those files to server, Before that we need to add servers in remote list of git • $ git remote add <AnyUniqueName> <gitpath> • Note : Mostly “origin” is used for remote name • Example : git remote add origin https://github.com/user/repo.git
  7. 7. Get List of all Remote Added • $git remote
  8. 8. How Authentication works for remote • To push anything on remote Git server, we need to authenticate our self. • For this, we need to generate RSA key and store in remote git server. This is only one time process. You can refer below articles • Generate RSA key using Eclipse • Creating First Application in Heroku using Eclipse • Working with Git on Window • How to add public key in Bit bucket
  9. 9. Push Changes • Once remote repository is added we can push changes from local to remote repository • To check available remote repositories run - $git remote • $ Git push <RemoteNameAdded> <localBranchName> • Example : git push origin master
  10. 10. Push Fast Forward (Not Recommended) • You may get an error about fast-forward while committing to remote repository. This is because you remote repository already have some file which is not in synch with your local repository • Correct solution is to fetch from remote repository, merge and then try to commit again • However, in case you want to overwrite [Yes, Overwrite means you cannot see any history] remote files we can use “-fast” attribute • Example : git push origin master --fast

×