In this Blog, we will see how to configure and use Git to Pull and Push Data.
Assumption: Git is already installed in your Machine. If not, you can refer to Install Git on Linux, Mac or Windows
Download Project from Git Repository (Github/Bitbucket)
There are 2 ways to use Git => SSH/HTTPS
- You need to add your SSH key to Github or Bitbucket Account. In order to Pull/Push repository.
- Your key will be located in homedirectory/.ssh/id_rsa.pub
- Use this command to print your public key.
- If your Output is success i.e you already have key. Just copy that key content and add in Github/Bitbucket accout setting => Access Key. Or you might need to give this key to Admin to add in Account.
- If your output is error i.e No such file or directory. It means there is no key with the name id_rsa.pub.
- In order to generate ssh Key, you can type ssh-keygen (Mac/Linux) in the terminal and follow instructions.
- For windows to generate key you can use putty or do manually like this in Command Prompt/Terminal
- At the end public and Private key will be generated in homedirectory/.ssh/ folder.
- Now you can try printing it and add in Github/Bitbucket setting => Access Key
- You don’t need to configure anything for HTTPS. The only catch is you will have to enter the Github/Bitbucket password to Pull/Push each time.
Get Repository URL
- Now once your method to Pull/Push is defined. We need to get Repository URL.
- You can ask for it to admin or get it from Github/Bitbucket account if you have access to it.
- You need to go to the specific repository and Right Corner there will be Option to Clone or Download.
- You can also select type there (SSH/HTTPS)
- Sample URLs
- Now you can Pull Repository.
- Code will be cloned in the current folder you are in.
Add a new Repository to Git (Github/Bitbucket)
- Lets say you have created a new Project and want to add it to Git(Github/Bitbucket).
- The only thing you need to do is create an Empty Repository in Github/Bitbucket prior to Upload.
- Once you have added an Empty Repository you can get newly create Repository URL
- Now let’s say your project is in the following location /home/ubuntu/myproject.
- You need to do following
- After push command, you will get success msg saying xx files pushed.
- If you get error check for username and email
- If you dont get any output for name and email you need to tell git who is pushing code.
- You can set using this
General Cycle to Pull Push Code
- After you have done all changes do following