Git Comands to Remember

Git Comands to Remember

Been working with Git for a few years now and I have to say memory isnt my strong suit. I have these commands noted and refer to them often. Here are the commands that get me up and "sycning" to my get repos.

Intiailze the repo locally

git init

Add all files in current and subdirectories to git

git add -A

Create initial commit with init as the message

git commit -m "init"

or

git commit -m "INSERT YOUR MESSAGE HERE"

Add your remote repo for backup, you can find this from your remote repo provider. A few options: github.com bitbucket.com gitlab.com

git remote add origin https://userid@bitbucket.org/userid/repo_name.git

Now that we have our repo iniilzaized, added all our files, committed them and added the remote repo, its time to push our local git to the remote master. This may prompt for a username/password, this you should have setup with your repo provider

git push origin master

If you have any questions please let me know. Hop this helps someone.

Error resolution:
Error I received at one point or another:

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

❯ ssh-add -l
The agent has no identities.
❯ ssh-add ~/.ssh/YOURKEY.pem
Identity added: /Users/userid/.ssh/YOURKEY.pem (/Users/userid/.ssh/YOURKEY.pem)
❯ git push --set-upstream origin master

When fetching master branch, the files do not reflect the master state:

git fetch origin

reset your local to master

git reset --hard origin/master


Share Tweet Send
0 Comments
Loading...
You've successfully subscribed to Metristech
Great! Next, complete checkout for full access to Metristech
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.