How to use git pull
How to use git pull function? Let me tell you how I would usually push my first initial commit onto GitHub IF I already had some files on my local directory i.e. laptop.
-
I’d create a new repository on GitHub and initialize it with a README file.
-
I would then proceed to clone this onto my local directory (most of the time my desktop — make sure to cd into that folder):
$ cd Desktop $ git clone https://github.com/USERNAME/REPOSITORY_NAME.git FOLDER_NAME
-
The link above is the remote URL which you can find in your GitHub repository by clicking the green button that says ‘Clone or Download’.
-
FOLDER_NAME is the name I want to give to my local folder; if I left this blank, it will automatically give the folder name the actual repository name I gave it on GitHub
-
This command also automatically sets your remote URL as the origin
-
-
This will create a local copy of the repository on my local machine and will contain the README file.
-
Then I would copy/cut all the files that I want to push to GitHub and paste them into the new folder containing the README file.
There is nothing wrong with doing it this way but I knew there was a way to do this without copying and pasting files and just using the command line.
- - -
How to do it with just the command line
-
Create a new repository on GitHub and initialize it with a README file
-
Create a folder on your local machine
-
Open terminal and move to that folder
$ cd FOLDER
-
Add the remote URL as origin
$ git remote add origin https://github.com/USERNAME/REPOSITORY_NAME.git
-
Now using the pull command, you can ‘pull’ down the README file onto the local folder
$ git pull origin master
-
Add your current files in the local folder to the staging area
$ git add –-all
-
Commit your changes
$ git commit -m "your commit message e.g. First commit"
-
Push your changes to the master branch
$ git push origin master
So happy I can finally do it with the command line as oppose to faffing around with copying and pasting my files onto a cloned repository.
Hopefully this will also help those who are new to using Git and GitHub!
- - -
This blog post has also been published on medium.