• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

Git

Git Reset File From Master

May 28, 2022

Here’s how to reset a file from the master branch.

git checkout origin/master test.py

git checkout origin/master test.py

This will undo your changes and matches what’s in the master repo.

Filed Under: Git Tagged With: git, master, reset

Git Reset Hard

February 12, 2022

Reset uncommitted changes to both files and directories.

git reset --hard

git reset --hard

Remove untracked files and directories.

git clean -fd

git clean -fd

Filed Under: Git Tagged With: changes, hard, reset, uncommitted

Git Diff Head

September 3, 2019

Here’s how to check what’s changed in your local Git repo vs the master repo.

Git Status tells you what file has changed, but not to the level of detail such as what lines or what code was changed.

git diff HEAD

git diff HEAD

Filed Under: Git Tagged With: compare, diff, git, head

Storing Git Credentials

February 9, 2019

There are two ways to store git credentials. One is temporary and the other permanent. You can store your git credentials unencrypted on disk forever or in cache memory temporarily.

Temporary. Store for 15 minutes.

git config credential.helper 'cache --timeout=900'

git config credential.helper 'cache --timeout=900'

Permanent.

git config credential.helper store
git push http://example.com/repo.git
Username: <type your username>
Password: <type your password>

git config credential.helper store git push http://example.com/repo.git Username: <type your username> Password: <type your password>

Next time you use git, you will not be prompted for a password.

Filed Under: Git, Linux Tagged With: cache, credentials, disk, git, permanent, store, temporary

Gitlab Community Edition

February 7, 2017

Git is the most popular version control software for managing your code. If you’re looking for the best version control system out there, Git is the pretty much the de-facto standard of version control. Although you can run Git locally without a server, you’ll need some kind of repository to share your code with others.

Enter Github. Github provide free and paid Git repositories. Github public repositories are free, while private ones require subscription. For $7 dollars a month, you can have up to 5 private repositories. For $50 per month, you can use up to 50 repositories.

If you want to run your own Git repository either on the cloud or on your own private network (it’s more secure this way), then you’ll need to look at Gitlab’s Community Edition (Github.com is proprietary). Gitlab requires that you install their software on a Linux server (I’m using Ubuntu Server).

I tried running Gitlab CE on the cheapest server ($5 per month) I can find at Digital Ocean. It works but, it’s painfully slow. I don’t recommend it. The $5 per month server only has 1 CPU core and 512 MB of RAM. I recommend that you go for a system that has 2 CPU cores and 2GB of RAM. This system will cost $20 per month.

By the way, if you don’t want managing your own server, you can simply sign up with Gitlab.com. It’s free! They offer unlimited private and public repositories up to 10GB of disk space per project. Of course, Gitlab has other products. For a paid subscription you can get enterprise support and more advanced features.

Visit Gitlab for more details.

Filed Under: Git, Linux Tagged With: git, github, gitlab, version control

Remove Sensitive Info From Github

June 1, 2015

I made a mistake by publishing my database password to an environment file that’s visible. Rookie mistake. Replacing the database password entry with something else and submitting kinda takes care of the problem, but anyone can still view the history of the file and see your password. One way of getting rid of this, if you don’t really care about the history of your submits, is to reinitialize the project back to the initial commit. Here’s how.

// Clone the project to your local computer
$ git clone https://github.com/name/myproject.git
 
// go to your project directory
$ cd myproject
 
// delete the .git folder where all the history is kept
$ rm -rf .git
 
// reinitialize your repository
$ git init
 
// add Github url
$ git remote add origin https://github.com/name/myproject.git
 
// verify remote
$ git remote -v
 
// Add all files and commit the changes
$ git add --all
$ git commit -am 'initial commit'
 
// Finally, push to the origin server which is Github
$ git push -f origin master

// Clone the project to your local computer $ git clone https://github.com/name/myproject.git // go to your project directory $ cd myproject // delete the .git folder where all the history is kept $ rm -rf .git // reinitialize your repository $ git init // add Github url $ git remote add origin https://github.com/name/myproject.git // verify remote $ git remote -v // Add all files and commit the changes $ git add --all $ git commit -am 'initial commit' // Finally, push to the origin server which is Github $ git push -f origin master

Your sensitive data is now gone from history. Just be careful next time.

Filed Under: Git Tagged With: git, init, sensitive

Setup New Repository on GitHub

February 2, 2015

The following instructions will create a new repository on GitHub. These instructions will assume that you’re logged in to GitHub.com. You can create a new repository by clicking on the link called “create a new repository” found on several pages on GitHub. You can also go directly to this URL: https://github.com/new.

You need to provide a repository name that’s hopefully short and memorable. Click the “Create Repository” button to start the initiation process. Once the repository is created, you can create a new local repository on your computer and sync it to GitHub repository.

On your computer:

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

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

If you have an existing local repository, you can push it to GitHub.

git remote add origin https://github.com/ulyssesr/RepositoryName.git
git push -u origin master

git remote add origin https://github.com/ulyssesr/RepositoryName.git git push -u origin master

Filed Under: Git Tagged With: new repository

Gitignore

January 22, 2014

You can ignore specific files in Git by placing a .gitignore file at the root of your local repository. The files listed in .gitignore will not be tracked by Git. Why would you do this? Well, there are certain OS generated files placed in system folders such as .DS_Store or Thumbs.db that are not really part of your code.

Create a .gitignore file

touch .gitignore

touch .gitignore

Edit the .gitignore file

sudo nano .gitignore

sudo nano .gitignore

Add the files you want excluded. You can use wildcards.

.DS_Store
Thumbs.db
*.log

.DS_Store Thumbs.db *.log

Commit and Push

git commit -m "adding .gitignore file" -a
git push

git commit -m "adding .gitignore file" -a git push

That should do it!

Filed Under: Git Tagged With: .gitignore, git, version control

  • Go to page 1
  • Go to page 2
  • Go to page 3
  • Go to Next Page »
  • Home
  • About
  • Archives

Copyright © 2023