34
loading...
This website collects cookies to deliver better user experience
git init
command. This command is how you create, or initialize, a new project repository on your local machine. When you run the command above in the terminal and then run the ls -la
command, you will see a folder named .git listed in the project structure. This folder is used to store project data that is used to keep track of changes occurring in each file.
Once you have initialized the repository, you will want to add a file from your text editor to your local repository. For example, I have a file named index.html that needs to be added to my local repository. In the terminal, I am going to run git add index.html
. This command moves the index.html file from the working environment into the staging environment. The staging environment is for files that are ready to be added to the repository.
If you run the command git status
, you will be able to see that index.html has been added to the staging environment, but has yet to be committed.
To commit a file, use the git commit -m "commit message here"
command. When a file change has been committed, it updates the .git folder that will save the current state of that file. To verify that this has been done, run the git log
command to view information on commit history.
Run the git branch
command to see what branch you are on. Git defaults to the master branch, but you are able to change the name if you want to. If you would like to change the name of this branch, you can run git branch -M “newBranchNameHere”
.
git remote add origin https://github.com/ceblakely/practice1.git
connects your local repository to the GitHub repository where your commits will be published. The term origin
is the universally accepted term for the remote repository, but you could change the name if you wanted to. Lastly, run the git push -u origin master
command to push index.html from the local repository to the remote repository on the master branch.If you wanted to add all files in your project to the staging area, instead of one at a time, run the command git add .
Note the difference between staging, committing, and pushing.
Staging
Committing
Pushing
Branches are used to save different states of the code. You can have production-ready code on the master branch, create another branch named main
and try out new features on that branch without affecting the deployed code. If you wanted to create a different branch to experiment, use the command git branch branchNameHere
.
I know the GitHub documentation can be a bit overwhelming, so I hope this helps someone getting started with GitHub! 💫