Working Around With GIT

Working away with GIT can be tedious especially for a newbie. Following GIT commands will help you accomplish many things with GIT. I took the commands from the GIT website. But sometimes it may not be quite straightforward to find these combinations of commands.

Creating a new repository on the command line locally and pushing the changes to it and the remote repository.

echo "# Echo-Oracle" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/adilraja/Echo-Oracle.git
git push -u origin master

Pushing an existing local repository to a remote repository from the command line.

git remote add origin https://github.com/adilraja/Echo-Oracle.git
git push -u origin master

Import code from another repository

Undoing changes on the remote repository

If by chance you have made unintended changes to your remote repository, by adding a new commit to it, you can undo the changes using the following commands.

git reset 7f6d03 --hard
 git push origin -f

Replace the number above in your reset command with the SHA of the commit that you want to revert to on the remote repository.

I found the following commands on GitLab. You might find these useful too.

Command line instructions

Git global setup
git config --global user.name "Adil Raja"
git config --global user.email "[email protected]"
Create a new repository
git clone https://gitlab.com/adilraja/evolutionary-nursery.git
cd evolutionary-nursery
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master
Existing folder or Git repository
cd existing_folder
git init
git remote add origin https://gitlab.com/adilraja/evolutionary-nursery.git
git add .
git commit
git push -u origin master

Here is a great tutorial on git.

Try Git

 

Photo by spencer77

If you found an error, highlight it and press Shift + Enter or click here to inform us.

CC BY-NC-ND 4.0 Working Around With GIT by Psyops Prime is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.

Leave a Reply